Differences between Linux system calls and library function calls

Source: Internet
Author: User

System calls occur in kernel space, so if you use system calls for file operations in a generic application in user space, there is a cost of user-space-to-kernel-space switching. In fact, even if the library function is used in user space to manipulate the file, because the file always exists on the storage medium, both the read and write operations, which are the operations of the hardware ( memory ) , will inevitably cause system calls. In other words, the operation of a library function on a file is actually implemented through a system call. For example , the C library function fwrite () is implemented through the write () system call.

In this case, using library functions also has the overhead of system calls, so why not use system calls directly? This is because the use of library functions can greatly reduce the number of system calls, since the read-write file is usually a large amount of data ( which is a large number of data manipulation units implemented relative to the underlying driver's system call ). This result is also due to the buffer technology. In both user and kernel space, buffers are used for file operations, such as writing files with fwrite , which writes the contents to the user space buffer, and writes the contents of the user buffer to the kernel buffer when the user space buffer is full or the write operation ends.

Differences between Linux system calls and library function calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.