- Any single-CPU computer can execute only one instruction at a time. If a process is running a user program in user mode and needs a system service, such as reading a data from a file, it has to execute a trap instruction to transfer control to the OS.
- System calls provide an interface to the services made available by an OS. These calls are generally available as routines written in C and C++, although certain low-level tasks (for example, tasks where hardware must be accessed directly), may need to be written using assembly-language instructions.
- To illustrate how system calls are used: writing a simple program to read data from one file and copy them to another file. The system-call sequence is shown in Fig. 2.29.
Example of how system calls are used.
- As we can see, even simple programs may make heavy use of the OS. Frequently, systems execute thousands of system calls per second.
- The run-time support system (a set of functions built into libraries included with a compiler) for most programming languages provides a system-call interface that serves as the link to system calls made available by the OS.
- Typically, a number is associated with each system call, and the system-call interface maintains a table indexed according to these numbers. The system call interface then invokes the intended system call in the OS kernel and returns the status of the system call and any return values.
- The relationship between an application program interface (API), the system-call interface, and the OS is shown in Fig. 2.30, which illustrates how the OS handles a user application invoking the open() system call.
The handling of a user application invoking the open() system call.
- Three general methods are used to pass parameters to the OS.
- The simplest approach is to pass the parameters in registers. In some cases, however, there may be more parameters than registers. In these cases, the parameters are generally stored in a block, or table, in memory, and the address of the block is passed as a parameter in a register (see Fig. 2.31). This is the approach taken by Linux and Solaris.
Passing of parameters as a table.
- Parameters also can be placed, or pushed, onto the stack by the program and popped off the stack by the OS.
- Some OSs prefer the block or stack method, because those approaches do not limit the number or length of parameters being passed.