In computing, a system call is the mechanism used by an application program to request service from the operating system, or more specifically, the operating system kernel.
Modern processors can typically execute instructions in several differently privileged states. In systems with two levels, they are usually called user mode and supervisor mode. Different privilege levels are provided so that operating systems can restrict the operations that programs running under them can perform, for reasons of security and stability. Such operations include accessing hardware devices, enabling and disabling interrupts, changing privileged processor state, and accessing memory management units. The operating system kernel would run in supervisor mode, and user applications in user mode.
With the development of separate operating modes with varying levels of privilege, a mechanism was needed for transferring control safely from lesser privileged modes to higher privileged modes. Less privileged code could not simply transfer control to more privileged code at any arbitrary point and with any arbitrary processor state; to allow it to do so could allow it to break security. For instance, the less privileged code could cause the higher privileged code to execute in the wrong order, or provide it with a bad stack.
System calls often use a special CPU instruction which causes the processor to transfer control to more privileged code, as previously specified by the more privileged code. This allows the more privileged code to specify where it will be entered as well as important processor state at the time of entry.
When the system call is invoked, the program which invoked it is interrupted, and information needed to continue its execution later is saved. The processor then begins executing the higher privileged code, which, by examining processor state set by the less privileged code and/or its stack, determines what is being requested. When it is finished, it returns to the program, restoring the saved state, and the program continues executing.
Note that in many cases, the actual return to the program may not be immediate. If the system call performs any kind of lengthy I/O operation, for instance disk or network access, the program may be suspended (“blocked”) and taken off the “ready” queue until the operation is complete, at which point the operating system will again make it a candidate for execution.
Generally, operating systems provide a library that sits between normal programs and the rest of the operating system, usually the C library (libc), such as glibc and MS LibC. This library handles the low-level details of passing information to the kernel and switching to supervisor mode, as well as any data processing and preparation which does not need to be done in privileged mode. Ideally, this reduces the coupling between the operating system and the application, and increases portability.
On exokernel based systems, the library is especially important as an intermediary. On exokernels LibOSes shield user applications from the very low level kernel API, and provide abstractions and resource management.
On POSIX and similar systems, popular system calls are open, read, write, close, wait, execve, fork, and kill. Many of today's operating systems have hundreds of system calls. For example, Linux almost has 300 different system calls. FreeBSD has about the same (almost 330).
Operating system technology | Application programming interfaces | Systems
Systemkald | Systemaufruf | קריאת מערכת | Wywołanie systemowe | Chamada de sistema | System call | Системный вызов
This article is licensed under the GNU Free Documentation License.
It uses material from the
"System call".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world