Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "C system calls" and "C library routines"?

Tags:

There are multiple sections in the manpages. Two of them are:

 2     Unix and C system calls 3     C Library routines for C programs 

For example there is getmntinfo(3) and getfsstat(2), both look like they do the same thing. When should one use which and what is the difference?

like image 787
Georg Schölly Avatar asked Feb 21 '09 13:02

Georg Schölly


People also ask

What is the difference between system call and library call?

A system call is a request made by the program to enter into kernel mode to access a process.. A library call is a request made by the program to access a library function defined in a programming library.

Does C library use system calls?

Programmers don't normally need to be concerned with system calls because there are functions in the GNU C Library to do virtually everything that system calls do. These functions work by making system calls themselves.

Do library functions use system calls?

Types of library functionsThere are library functions that do not make any system call.

Is printf is a system call?

printf() actually uses write() system call. The write() system call is actually responsible for sending data to the output.


2 Answers

System calls are operating system functions, like on UNIX, the malloc() function is built on top of the sbrk() system call (for resizing process memory space).

Libraries are just application code that's not part of the operating system and will often be available on more than one OS. They're basically the same as function calls within your own program.

The line can be a little blurry but just view system calls as kernel-level functionality.

like image 144
cletus Avatar answered Nov 10 '22 18:11

cletus


Libraries of common functions are built on top of the system call interface, but applications are free to use both.

System calls are like authentication keys which have the access to use kernel resources.

enter image description here

Above image is from Advanced Linux programming and helps to understand how the user apps interact with kernel.

like image 40
shingaridavesh Avatar answered Nov 10 '22 18:11

shingaridavesh