linux system calls, library functions and kernel function of the difference

Look at the system call, as well as library functions, previously did not understand, always thought that with the library function is the same system call, but know that this is not the same today.
Library functions is what we usually refer to the application programming interface API, which is actually a function definition, such as the common read (), write () functions such as instructions how to obtain a given service, but the system call is interrupted by the soft kernel to send a clear request, in addition kernel system call is completed, and user mode function is done in the library.
System call occurs in the kernel space, using the system call if the general user space application to perform file operations, there will be user space to kernel space switching overhead. In fact, even to operate the file because the file is always present on the storage medium, so whether read and write operations use the library functions in user space, are operating on the hardware (memory), and are bound to cause a system call. That is, the operation of the document library functions are actually implemented by the system call. For example C library function fwrite () is through the write () system call to achieve.
In this case, use the library functions have overhead of system calls, why not just use the system call it? This is because the read and write data files are usually large (this is a large amount of data relative to the operation of the drive unit of the underlying system calls implemented), then, using the library functions can significantly reduce the number of system calls. This result is due to a buffer and technology. In user space and kernel space, file operations use a buffer, such as writing a file with fwrite, contents are first written to the user space buffers, when the user space buffer is full or write operation is completed, the user will only buffer content area is written kernel buffer, the same token, when the buffer is full or when the kernel will write the end of the kernel buffer contents written to a file corresponding hardware medium.
System call and system command: system API command relatively higher level, each system command is an executable program, such as the commonly used system commands ls, hostname, etc., such as strace ls will find that they call such as open (), brk (), fstat (), ioctl () system calls.
System call is the user process enters the kernel interface layer, which itself is not a core function, but he is the function implemented by the kernel, the kernel into the system, different system calls will find their corresponding kernel function, this function is called to write the kernel system call "service routine." It can be said that the system call service routine package routines.

Guess you like

Origin www.cnblogs.com/dbalightyear/p/11280216.html
Recommended