4 Operating System Services Operating systems provide an environment for execution of programs and services to programs and usersOne set of operating-system services provides functions that are helpful to the user:User interface - Almost all operating systems have a user interface (UI).Varies between Command-Line (CLI), Graphics User Interface (GUI), BatchProgram execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error)I/O operations - A running program may require I/O, which may involve a file or an I/O deviceFile-system manipulation - The file system is of particular interest. Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.
5 Operating System Services (Cont.) Communications – Processes may exchange information, on the same computer or between computers over a networkCommunications may be via shared memory or through message passing (packets moved by the OS)Error detection – OS needs to be constantly aware of possible errorsMay occur in the CPU and memory hardware, in I/O devices, in user programFor each type of error, OS should take the appropriate action to ensure correct and consistent computingDebugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system
7 Operating System Services (Cont.) Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharingResource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of themMany types of resources - Some (such as CPU cycles, main memory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release codeAccounting - To keep track of which users use how much and what kinds of computer resourcesProtection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each otherProtection involves ensuring that all access to system resources is controlledSecurity of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attemptsIf a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as strong as its weakest link.
8 User Operating System Interface - CLI Command Line Interface (CLI) or command interpreter allows direct command entrySometimes implemented in kernel, sometimes by systems programSometimes multiple command interpreters – shells Examples are UNIX and LINUXPrimarily fetches a command from user and executes it
10 User Operating System Interface - GUI User-friendly desktop metaphor interfaceUsually mouse, keyboard, and monitorIcons represent files, programs, actions, etcVarious mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder)Invented at Xerox PARC in 1970sMany systems now include both CLI and GUI interfacesMicrosoft Windows is GUI with CLI “command” shellApple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath and shells availableSolaris is CLI with optional GUI interfaces (Java Desktop, KDE)
12 System call sequence to copy the contents of one file to another file Programming interface to the services provided by the OSTypically written in a high-level language (C or C++)System call sequence to copy the contents of one file to another file
13 System Calls Contd…Many System calls are required even to execute simple programs (around thousands of system calls per second)But application programmers develop programs according to Application Programming Interface(API).What is API? API specifies a set of functions that are available to an application programmer along with parameters passed and return values
14 Example of API Win32 API for windows systems POSIX API for POSIX-based systemsJava API for java virtual machineThere are benefits working with APIsProgram portabilityAPI are more easier to work withThere is a correlation between a function in API and an associated system call
15 Run time support system provides a system-call interface that serves as the link to system calls made available by the OS.System call Interface(SCI) intercepts function calls in the API and invokes the necessary system calls within the OSSCI invokes the intended system call in the OS kernel and returns the status of the system call and any return values
16 System Call Implementation The system-call interface intercepts function calls in the API and invokes the necessary system calls within the OS.Typically, a number associated with each system callSystem-call interface maintains a table indexed according to these numbersThe system call interface invokes intended system call in OS kernel and returns status of the system call and any return valuesThe caller need know nothing about how the system call is implementedJust needs to obey API and understand what OS will do as a result callMost details of OS interface hidden from programmer by APIManaged by run-time support library (set of functions built into libraries included with compiler)
18 Standard C Library Example C program invoking printf() library call, which calls write() system call
19 System Call Parameter Passing Often, more information is required than simply identity of desired system callExact type and amount of information vary according to OS and callThree general methods used to pass parameters to the OSSimplest: pass the parameters in registersIn some cases, may be more parameters than registersParameters stored in a block, or table, in memory, and address of block passed as a parameter in a registerThis approach taken by Linux and SolarisParameters placed, or pushed, onto the stack by the program and popped off the stack by the operating systemBlock and stack methods do not limit the number or length of parameters being passed
21 Types of System Calls Process control File management Device managementInformation maintenanceCommunicationsProtection
22 Process Control Process control End, abort Load, execute Create process, terminate processGet process attributes, set process attributesWait for timeWait event, signal eventAllocate and free memory
23 MS-DOS execution Program CI resumes execution Memory Instruction pointer is set to first instructionReloads the rest of CI from diskRuns successerrorCI makes error code available to the userError code saved(a) At system startup (b) running a program
27 Information Maintenance Get time or date , set time or dateGet system data , set system dataGet process, file or device attributesSet process, file or device attributes
28 Communication Create , delete communication connection Send , receive messagesTransfer status informationAttach or detach remote devices
29 Protection Set permission, get permission Allow user and deny user system calls
30 System BootThe process of starting a computer by loading the kernel is known as booting the systemSmall piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts itIn PCs there is a two-step process where a simple bootstrap loader fetches a more complex boot program from disk which loads the kernel.Tasks done by bootstrap programRun diagnostics to determine the state of the machineInitialize all aspects of the system from registers to device controllers.
31 System Boot Contd… Why EPROM is required? All ROM come under firmware Cell phones, PDAs store the entire OS in ROM, the entire OS is stored in ROM. Problems with this approach is, change in booting code necessitates change in codeAll ROM come under firmwareBoot disk or system disk has a boot partition
34 BIOSBIOS stands for Basic Input/Output SystemPerforms some system integrity checksSearches, loads, and executes the boot loader program.It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.So, in simple terms BIOS loads and executes the MBR boot loader.
36 MBR stands for Master Boot Record. It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sdaMBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.It contains information about GRUB (or LILO in old systems).So, in simple terms MBR loads and executes the GRUB boot loader.
38 GRUB stands for Grand Unified Bootloader. If you have multiple kernel images installed on your system, you can choose which one to be executed.GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
40 KernelMounts the root file system as specified in the “root=” in grub.confKernel executes the /sbin/init programSince init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.initrd stands for Initial RAM Disk.initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.
42 InitLooks at the /etc/inittab file to decide the Linux run level.Following are the available run levels0 – halt1 – Single user mode2 – Multiuser, without NFS3 – Full multiuser mode4 – unused5 – X116 – rebootInit identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run levelIf you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.Typically you would set the default run level to either 3 or 5.
44 Runlevel programsDepending on your default init level setting, the system will execute the programs from one of the following directories.Run level 0 – /etc/rc.d/rc0.d/Run level 1 – /etc/rc.d/rc1.d/Run level 2 – /etc/rc.d/rc2.d/Run level 3 – /etc/rc.d/rc3.d/Run level 4 – /etc/rc.d/rc4.d/Run level 5 – /etc/rc.d/rc5.d/Run level 6 – /etc/rc.d/rc6.d/Programs starts with S are used during startup. S for startup.Programs starts with K are used during shutdown. K for kill.There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
45 OS-Implementation Traditionally OS was written in assembly language Now in higher-level languages like C/C++Advantages of using higher-level languageCode can be written fasterMore compactEasier to understand and debugEasier to portDisadvantageReduced speedIncreased storage requirements