1 / 45

OS Services System calls and their types

OS Services System calls and their types. G.Anuradha. Objectives. Review of OS Services User OS-Interface Command Interpreter GUI System calls and their types. A View of Operating System Services. Operating System Services.

lilly
Download Presentation

OS Services System calls and their types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OS Services System calls and their types G.Anuradha

  2. Objectives • Review of OS Services • User OS-Interface • Command Interpreter • GUI • System calls and their types

  3. A View of Operating System Services

  4. Operating System Services • Operating systems provide an environment for execution of programs and services to programs and users • One 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), Batch • Program 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 device • File-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 network • Communications may be via shared memory or through message passing (packets moved by the OS) • Error detection – OS needs to be constantly aware of possible errors • May occur in the CPU and memory hardware, in I/O devices, in user program • For each type of error, OS should take the appropriate action to ensure correct and consistent computing • Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system

  6. Message passing and shared memory

  7. Operating System Services (Cont.) • Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing • Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them • Many 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 code • Accounting - To keep track of which users use how much and what kinds of computer resources • Protection 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 other • Protection involves ensuring that all access to system resources is controlled • Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts • If 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 interpreterallows direct command entry • Sometimes implemented in kernel, sometimes by systems program • Sometimes multiple command interpreters – shells Examples are UNIX and LINUX • Primarily fetches a command from user and executes it

  9. Bourne Shell Command Interpreter

  10. User Operating System Interface - GUI • User-friendly desktop metaphor interface • Usually mouse, keyboard, and monitor • Icons represent files, programs, actions, etc • Various 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 1970s • Many systems now include both CLI and GUI interfaces • Microsoft Windows is GUI with CLI “command” shell • Apple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath and shells available • Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)

  11. The Mac OS X GUI

  12. System Calls • Programming interface to the services provided by the OS • Typically 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 systems • Java API for java virtual machine • There are benefits working with APIs • Program portability • API are more easier to work with • There 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 OS SCI 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 call • System-call interface maintains a table indexed according to these numbers • The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values • The caller need know nothing about how the system call is implemented • Just needs to obey API and understand what OS will do as a result call • Most details of OS interface hidden from programmer by API • Managed by run-time support library (set of functions built into libraries included with compiler)

  17. API – System Call – OS Relationship

  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 call • Exact type and amount of information vary according to OS and call • Three general methods used to pass parameters to the OS • Simplest: pass the parameters in registers • In some cases, may be more parameters than registers • Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register • This approach taken by Linux and Solaris • Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system • Block and stack methods do not limit the number or length of parameters being passed

  20. Parameter Passing via Table

  21. Types of System Calls • Process control • File management • Device management • Information maintenance • Communications • Protection

  22. Process Control • Process control • End, abort • Load, execute • Create process, terminate process • Get process attributes, set process attributes • Wait for time • Wait event, signal event • Allocate and free memory

  23. MS-DOS execution Program CI resumes execution Memory Instruction pointer is set to first instruction Reloads the rest of CI from disk Runs success error CI makes error code available to the user Error code saved (a) At system startup (b) running a program

  24. FreeBSD Running Multiple Programs

  25. File Management • Create file, delete file • Open , close • Read , write , reposition • Get file attributes, set file attributes • File attributes: file name, file type, protection codes, accounting information

  26. Device Management • Request device, release device • Read , write , reposition • Get device attributes, set device attributes

  27. Information Maintenance • Get time or date , set time or date • Get system data , set system data • Get process, file or device attributes • Set process, file or device attributes

  28. Communication • Create , delete communication connection • Send , receive messages • Transfer status information • Attach or detach remote devices

  29. Protection • Set permission, get permission • Allow user and deny user system calls

  30. System Boot • The process of starting a computer by loading the kernel is known as bootingthe system • Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it • In 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 program • Run diagnostics to determine the state of the machine • Initialize all aspects of the system from registers to device controllers.

  31. System Boot Contd… • Why EPROM is required? • 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 code • All ROM come under firmware • Boot disk or system disk has a boot partition

  32. BIOS • BIOS stands for Basic Input/Output System • Performs some system integrity checks • Searches, 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.

  33. MBR • MBR stands for Master Boot Record. • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda • MBR 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.

  34. 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.

  35. Kernel • Mounts the root file system as specified in the “root=” in grub.conf • Kernel executes the /sbin/init program • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grepinit’ 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.

  36. Init • Looks at the /etc/inittab file to decide the Linux run level. • Following are the available run levels • 0 – halt • 1 – Single user mode • 2 – Multiuser, without NFS • 3 – Full multiuser mode • 4 – unused • 5 – X11 • 6 – reboot • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program. • Execute ‘grepinitdefault /etc/inittab’ on your system to identify the default run level • If 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.

  37. Runlevel programs Depending 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.

  38. OS-Implementation • Traditionally OS was written in assembly language • Now in higher-level languages like C/C++ • Advantages of using higher-level language • Code can be written faster • More compact • Easier to understand and debug • Easier to port • Disadvantage • Reduced speed • Increased storage requirements

More Related