System call vs Function call

后端 未结 10 673
遥遥无期
遥遥无期 2020-12-04 14:27

What is the difference between a system call and a function call? Is fopen() a system call or a function call?

相关标签:
10条回答
  • 2020-12-04 15:15

    Just to complete the picture presented by the others, fopen is commonly implemented as a wrapper around open, which is also a user-accessible function. fopen is, in a sense, higher-level than open since the FILE* structure it returns encapsulates stuff for the user. Some users use open directly for special needs. Therefore it wouldn't be right to call fopen a "system call" in any way. Nor does it execute system calls directly, since open is also a function callable by the user.

    0 讨论(0)
  • 2020-12-04 15:18

    fopen is a function call, but it may sometimes be referred to as a system call because it is ultimately handled by the "system" (the OS). fopen is built into the C runtime library.

    0 讨论(0)
  • 2020-12-04 15:21

    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.

    0 讨论(0)
  • 2020-12-04 15:22

    A system call is a call into kernel code, typically performed by executing an interrupt. The interrupt causes the kernel to take over and perform the requested action, then hands control back to the application. This mode switching is the reason that system calls are slower to execute than an equivalent application-level function.

    fopen is a function from the C library that, internally, performs one or more system calls. Generally, as a C programmer, you rarely need to use system calls because the C library wraps them for you.

    0 讨论(0)
提交回复
热议问题