1Definition
A System Call is a formal programmatic mechanism through which an application program executing in user mode requests privileged services—such as hardware access, process creation, file I/O, or inter-process communication—from the operating system kernel.
2Simple Explanation
User programs operate in a restricted sandbox. When a program wants to execute an action outside its sandbox (e.g., creating a file on disk or reading network packets), it cannot execute hardware instructions directly. Instead, it calls a standard library API (like glibc in C), which issues a System Call. The System Call triggers a CPU software interrupt, passing control to the Kernel's System Call Interface (SCI). The Kernel validates the request, performs the operation in Kernel Mode, and returns control back to the user program.
3Real-Life Example / Analogy
Ordering Food at a Drive-Thru Window: You (the user app) drive up to the intercom. You cannot walk inside the kitchen and operate the commercial deep fryers (hardware). You speak your order into the speaker (System Call API). The employee inside the restaurant (System Call Interface) receives the request, validates your order, has the kitchen staff prepare the food in the private kitchen (Kernel Space), and passes the bagged food through the window back to your car.
4Diagram / Visual Representation
5Working / How It Works
- User Invocation: User program executes high-level function wrapper (e.g.,
open(),read(),mkdir()). - System Call Number Setup: The library puts the corresponding system call index number into a designated CPU register (e.g.,
EAXon x86). - Trap Execution: A software interrupt (
sysenterorsyscallinstruction) is triggered. - Kernel Table Lookup: The CPU context switches to Kernel Mode. The SCI uses the index number to locate the target system call handler routine inside the kernel jump table.
- Execution & Return: Kernel executes procedure, stores return code in register, and executes return-from-interrupt instruction (
sysexit) to restore User Mode.
6Types / Components / Characteristics
Categories of System Calls:
- Process Control:
create process,terminate process,end,abort,load,execute,wait event,allocate memory. - File Management:
create file,delete file,open,close,read,write,reposition,chmod. - Device Management:
request device,release device,read,write,ioctl. - Information Maintenance:
get time/date,set system data,getpid,alarm. - Communication:
create pipe,send/receive messages,shmget,mmap.
- Process Control:
Windows vs. Unix API System Call Mapping:
| System Call Category | Windows Win32 API System Call | Unix / Linux POSIX System Call |
|---|---|---|
| Process Control | CreateProcess(), ExitProcess(), WaitForSingleObject() |
fork(), exec(), exit(), wait() |
| File Management | CreateFile(), ReadFile(), WriteFile(), CloseHandle() |
open(), read(), write(), close(), chmod() |
| Device Management | SetConsoleMode(), ReadConsole(), WriteConsole() |
ioctl(), read(), write() |
| Info Maintenance | GetCurrentProcessID(), SetTimer(), Sleep() |
getpid(), alarm(), sleep() |
| Communication | CreatePipe(), CreateFileMapping(), MapViewOfFile() |
pipe(), shmget(), mmap() |
7Solved Examples / Problems
Problem: Explain how the Unix fork() system call operates during process creation.
Solution:
- When a process calls
fork(), the kernel creates an exact duplicate child process sharing the parent's file descriptors. - The
fork()system call returns twice:- It returns the Child's Process ID (PID > 0) to the Parent Process.
- It returns
0to the Child Process.
- If process creation fails, it returns
-1to the parent.
8Advantages, Disadvantages & Applications
- Advantages: Protects hardware integrity, enforces security policies, delivers cross-hardware API uniformity.
- Disadvantages: Switching between user mode and kernel mode introduces CPU pipeline stall overhead.
9Important Points to Remember
- System calls are implemented natively in low-level C and Assembly.
- System calls represent the only valid mechanism for an unprivileged process to enter Kernel Mode.
10Test Your Understanding
- MCQ: Which of the following represents the equivalent Unix POSIX system call for Windows
CreateProcess()?- A)
open() - B)
fork() - C)
ioctl() - D)
shmget()
Show answer
B. - A)
- Conceptual Question: Describe the sequence of hardware and software events during a system call context switch.
- Application Question: Write a short C pseudocode block demonstrating how a program checks if it is executing as a parent or child process after calling
fork().
