Sobes.tech
Junior — Middle

How does executing a function inside a program differ from calling system services of the Linux operating system?

sobes.tech AI

Answer from AI

Executing a function within a program is a call to code that runs in the context of the current process and directly uses the resources of that process. It is usually fast and does not require a context switch.

Calling Linux system services (via system calls) is a request to the operating system kernel to perform certain operations (e.g., working with files, network, processes). Such a call requires switching from user mode to kernel mode, which is more costly in terms of time and resources.

Key differences:

  • A function executes in user space, while a system call executes in kernel space.
  • System calls provide access to hardware resources and protected OS functions.
  • System calls are slower due to the context switch.

Example: reading a file within a program — a call to the fread() function, which ultimately invokes the read() system call to retrieve data from a file.