A system call is a request made by a program to the operating system. It allows an application to access functions and commands from the operating system's API.
System calls perform system-level operations, such as communicating with hardware devices and reading and writing files. By making system calls, developers can use pre-written functions supported by the operating system (OS) instead of writing them from scratch. This simplifies development, improves app stability, and makes apps more "portable" between different versions of an OS.
How System Calls Work
Applications run within an area of memory called user space. A system call accesses the operating system kernel, which runs in kernel space. When an application makes a system call, it must first request permission from the kernel. This may be done with an interrupt request, which pauses the current process and transfers control to the kernel.
If the request is allowed, the kernel processes the request, such as creating or deleting a file. When the operation is complete, the kernel passes the output back to the application, which transfers data from the kernel space to the user space in memory. The application receives the output from the kernel as input. In the source code of a program, this may be a parameter value or a return value within a function. Once the input is received, the application resumes the process.
A basic system call, such as getting the system date and time, may take a few nanoseconds. A more advanced system call, such as establishing communication with a network device may require a few seconds. In order to prevent bottlenecks, most operating systems initiate a separate kernel thread for each system call. Modern operating systems are multithreaded, meaning they can process multiple system calls at one time.