100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What Are the Types of System Calls?

Learn the five types of system calls, the trap/mode-switch mechanism, and syscall vs library calls — with OS interview questions answered.

mediumQ132 of 224 in Operating Systems Est. time: 6 minsLast updated:
Open Code Lab

Expected Interview Answer

System calls are the controlled entry points through which a user-space program requests a privileged service from the kernel, and they fall into five broad categories: process control, file management, device management, information maintenance, and communication.

Process control calls (fork, exec, exit, wait) create, terminate, and manage processes; file management calls (open, read, write, close) operate on files and directories; device management calls (ioctl, read, write on device files) interact with peripheral hardware through a uniform interface; information maintenance calls (getpid, alarm, sleep) query or set OS and process attributes; and communication calls (pipe, shmget, send, recv) let processes exchange data, either directly via message passing or indirectly via shared memory. Each system call triggers a controlled trap into kernel mode — typically via a dedicated instruction like syscall on x86-64 — where the CPU privilege level switches from user to kernel, arguments are validated, the kernel performs the requested privileged operation, and control returns to user mode with a result. This trap mechanism is precisely what separates a system call from an ordinary library function call: a system call always crosses the user/kernel boundary and is mediated by the OS, while a library call executes entirely in user space unless it happens to wrap a system call internally.

  • Provides a controlled, validated boundary between user programs and the kernel
  • Categorization (process, file, device, info, communication) organizes the entire OS API surface
  • The trap/mode-switch mechanism enforces protection and prevents arbitrary privileged access
  • Understanding it clarifies the difference between a system call and a regular library call

AI Mentor Explanation

System calls are like a player who cannot personally change the field placements, call for a review, or bring on a new bowler — those all require formally requesting the umpire or captain, who is the only authority permitted to act. Process control is like requesting a substitute fielder; file management is like requesting the scorebook be updated; communication is like a fielder radioing the captain. Every request crosses a controlled boundary through the umpire, exactly like a system call crossing into kernel mode.

Step-by-Step Explanation

  1. Step 1

    User program issues request

    Code calls a wrapper like read() or fork(), which prepares arguments and a syscall number.

  2. Step 2

    Trap into kernel mode

    A dedicated instruction (e.g. syscall on x86-64) triggers a mode switch from user to kernel privilege.

  3. Step 3

    Kernel validates and executes

    The kernel checks arguments, verifies permissions, and performs the privileged operation (file I/O, process creation, etc).

  4. Step 4

    Return to user mode

    The kernel places the result in a register and switches privilege back to user mode, resuming the calling program.

What Interviewer Expects

  • Ability to name and give an example of at least three of the five system call categories
  • Clear explanation of the trap/mode-switch mechanism crossing the user/kernel boundary
  • Correctly distinguishing a system call from an ordinary library function call
  • A concrete example syscall (fork, read, ioctl) tied to its category

Common Mistakes

  • Treating every library function (like printf) as a system call itself
  • Forgetting device management as a distinct category from file management
  • Not knowing that a system call triggers a privilege-level (mode) switch
  • Confusing communication system calls (pipe, shared memory) with networking protocols

Best Answer (HR Friendly)

System calls are the official, controlled ways a regular program asks the operating system to do something privileged, like creating a process, reading a file, or talking to a device — they generally fall into categories like process control, file management, device management, information queries, and communication. Every one of these requests briefly switches the CPU into a protected kernel mode so the request can be validated and safely carried out before returning control to the program.

Code Example

Examples spanning the five system call categories
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>

int main(void) {
    pid_t pid = fork();            /* process control: create a new process */

    if (pid == 0) {
        int fd = open("out.txt", O_WRONLY | O_CREAT, 0644);  /* file management */
        write(fd, "done\n", 5);     /* file management */
        close(fd);
        _exit(0);                  /* process control: terminate */
    } else {
        int status;
        wait(&status);              /* process control: wait for child */
        pid_t self = getpid();      /* information maintenance */
        (void)self;
    }
    return 0;
}

Follow-up Questions

  • What is the difference between a system call and a library function call?
  • What happens to the CPU privilege level during a system call trap?
  • How does ioctl differ from read and write for device management?
  • Why are shared memory and pipes both classified as communication system calls?

MCQ Practice

1. Which of these is a process control system call?

fork() creates a new process, making it a classic process control system call, unlike file, device, or communication calls.

2. What fundamentally distinguishes a system call from a regular library function?

A system call always transitions the CPU from user mode to kernel mode via a trap instruction; a plain library call does not, unless it wraps a syscall.

3. Which category do shared memory and message passing system calls belong to?

shmget, pipe, send, and recv let processes exchange data, placing them in the communication category of system calls.

Flash Cards

Name the five system call categories.Process control, file management, device management, information maintenance, communication.

What triggers the user-to-kernel mode switch?A dedicated trap instruction (e.g. syscall on x86-64) issued by the system call wrapper.

Give one example of each: process control, file management.Process control: fork(). File management: read()/write()/open().

System call vs library call?A system call crosses into kernel mode via a trap; a library call runs entirely in user space unless it wraps a syscall.

1 / 4

Continue Learning