Why do I need a system call? There are two main reasons for this.
(1) system calls can provide user space with a unified interface for accessing hardware resources, so that applications do not have to focus on specific hardware access operations. For example, when reading and writing files, the application does not have to worry about the type of disk, or even the file system.
(2) system call can protect the system, ensure the stability and security of the system. The existence of a system call specifies how the user process enters the kernel, in other words, the path of the user's access to the kernel is predetermined and can only be entered into the kernel from the specified location, without allowing arbitrary jumping into the kernel. The security of the kernel can be ensured by having such a unified access path restriction into the kernel.
(3) The system call has a stronger function.
The difference between a system call and a library function:
1. The system is called to facilitate the application of the interface using the operating system, and the library function is to facilitate people to write applications, such as you write a function you can actually say is a library function.
2. The system call can be understood as the kernel provided to us in the User state interface function, can be considered to be some kind of kernel library function.
3. The main role of the operating system API is to fully display the functions of the operating system, to provide applications, based on the operating system, and file, memory, clock, network, graphics, various peripherals and other interoperability capabilities. In addition, operating system APIs often provide functionality for many tool classes, such as manipulating strings, various data types, time dates, and so on. There is a direct relationship between the API function and the system call, an API function can be implemented by a system call, can be implemented by invoking multiple system calls, and no system calls can be used at all.
4. System call efficiency is not necessarily higher than the library function