What is the difference between a system call and a function call? Is fopen() a system call or a function call?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
If you're using Linux you can monitor system calls performed by an application:
strace appname ...
Its output might give you a good insight on what's going on within libc, and which functions are actually system calls.
A point of view to add to this discussion is that a function call generally in the most optimistic case has overhead of a a few 8-bit instructions (4-10 on average)in x86.
A system call has the following properties.
For these three primitive reasons (there are probably more), one should reduce the amount of system calls where possible -- e.g., networked system software keeps socket handles (and other application specific internal data structures used by a connection) around to assign to new connection, why bother the kernel ?
Remember that software is built like a upside down pyramid. System calls are at the base.
The question has excellent answers already, but I think I can add something (one segment from ostepthat isn't already in other answers
Sometimes system call and function call have the same signature, for example,
open()
:open()
-system callopen()
-function callQuoting form OSTEP
System call is executed at kernet level and not in user spce because it requires some prievilege to access the hardware.
Therfore when programming in user space and making some ordinary function call like
fopen
in C language the libc generally wrap this function to specific code code where an interrupt is generated to switch from user space to kernel space , then in kernel space the required system call to perform the functionality of the function call at hardware level will be executed in kernel space .