Linux system calls
System call refers to a set of "special" interfaces that the operating system provides to a user program, which can be used by the user program to obtain the services provided by the operating system kernel.
Why can't a user program directly access the services provided by the system kernel? This is because in Linux, in order to better protect the kernel space, the operating space of the program is divided into user space and kernel space (that is, often called user state and kernel state), they run at different levels, logically separated from each other. Therefore, user processes typically do not allow access to kernel data or kernel functions, they can only manipulate user data in user space and invoke user-space functions.
However, in some cases, the process of user space needs to obtain a certain system services (invoke kernel space program), then the operating system must use the system to provide the user's "special interface" ——— system calls to specify the user process into the kernel space specific location. When making the system call, the program running space needs to enter the kernel space from the user space, the processing completes then returns the user space.
Linux system calls are streamlined (only about 250), and it inherits the most basic and useful parts of UNIX system calls. According to the functional logic, these system calls can be divided into process control, interprocess communication, file system control, storage management, network management, socket control, user management and other categories.
User programming Interface (API)
The system call mentioned earlier does not interact directly with the programmer, it is simply an interface that submits a request to the kernel through a soft interrupt mechanism to obtain the kernel service. In practice, programmers often invoke user programming interfaces (APIs).
For example, the API function for creating a process fork () function corresponds to a sys_fork () system call to kernel space, but not all functions correspond to one system call. Sometimes, an API function requires several system calls to work together to complete functions, and even some API functions do not need to invoke the corresponding system call (so it does not perform the service provided by the kernel).
System commands
The system command is a layer higher than the API, it is actually an executable program, its internal reference user programming interface (API) to implement the corresponding functions, the relationship between them is as follows Figure 1: