What is a system call?

Why Interviewers Ask This

This is a classic screening question for Operating Systems roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

A system call is the mechanism by which a user-mode program requests a service from the operating system kernel — the interface between user applications and the OS. When a program needs to: read/write files, allocate memory, create processes, communicate via network, access devices — it uses system calls because these operations require kernel privileges. Common system calls: Process: fork(), exec(), exit(), wait(), getpid(). File I/O: open(), read(), write(), close(), lseek(), stat(). Memory: brk(), mmap(), munmap(). Network: socket(), bind(), listen(), accept(), connect(), send(), recv(). Device: ioctl(). IPC: pipe(), shmget(), msgget(). System call execution: (1) User program calls library function (printf, fread, malloc); (2) Library function sets up system call number and arguments; (3) Executes SYSCALL instruction → CPU traps to kernel; (4) Kernel handler looks up system call table by number; (5) Validates parameters, executes privileged operation; (6) Returns result via return register; (7) CPU returns to user mode. Overhead: system calls are expensive relative to function calls — mode switch, parameter validation, kernel execution, mode switch back. Minimize unnecessary syscalls. Buffered I/O (fread vs read) batches many small reads into one large syscall. strace command (Linux): traces all system calls made by a process — essential debugging tool: strace ls -la. VDSO (Virtual Dynamic Shared Object): kernel optimization — some syscalls (gettimeofday) executed in user mode by reading kernel-mapped memory — eliminates mode switch overhead.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Operating Systems experience.