Skip to content
We areTOP 1%

What is a system call? Name the common process-control and file-management calls.

EasyConceptOS Basics & System Calls
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A system call is the way a user program asks the kernel to do something it is not allowed to do itself, such as create a process or read a file. It looks like a function call, but it switches the CPU into kernel mode, the kernel does the work, and control returns with a result. The names below are the Unix/Linux (POSIX) ones; Windows has equivalents such as CreateProcess and ReadFile.

  • Process control: fork() creates a child process, exec() replaces the current program with a new one, wait() makes a parent wait for a child to finish, and exit() ends a process with a status code.
  • File management: open() returns a file descriptor (a small integer naming the open file), read() and write() transfer bytes, and close() releases the descriptor.
  • Other groups cover devices (ioctl()), information (getpid()) and communication (pipe(), socket()).

Example: copying a file in C:

int in  = open("a.txt", O_RDONLY);
int out = open("b.txt", O_WRONLY | O_CREAT, 0644);
char buf[512]; ssize_t n;
while ((n = read(in, buf, sizeof buf)) > 0)
    write(out, buf, n);
close(in); close(out);

On Linux, strace cp a.txt b.txt shows the same calls made by cp.

More in OS Basics & System Calls

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account