- LPU MCA Semester 1
- CAP366
- Unit 1
CAP366 · Unit 1: Introduction to operating systems
System calls
11 practice questions · in the MTE and ETE syllabus
Key points
- System call = trap into the kernel for a service
- APIs wrap system calls (printf -> write)
- fork creates, exec replaces the image, wait collects
- After successful exec the old code is gone, PID same
A system call is the programmatic interface by which a user program requests a kernel service. Executing it triggers a trap: the mode bit changes to kernel mode, the kernel service runs, and control returns to user mode.
Programs normally use an API (e.g. POSIX or the C library); the library function invokes the real system call (printf calls write).
| Category | Examples |
|---|---|
| Process control | fork, exec, wait, exit, abort |
| File management | open, read, write, close |
| Device management | ioctl, read, write |
| Information maintenance | getpid, time |
| Communication | pipe, shmget, send, receive |
| Protection | chmod, umask |
Typical shell flow: fork() creates a child copy, the child calls exec() to load a new program, the parent calls wait().
Exam pitfall: after a successful exec() the code that followed it never runs and the PID is unchanged; fork() returns 0 in the child and the child's PID in the parent, -1 on failure.
Try two questions
Why is the C library function printf() classed as a library routine rather than a system call?
- It runs in kernel mode and so is part of the kernel rather than a system call
- It formats data in user space and then invokes the write system call to reach the kernel
- It is a system call, but the shell hides the trap instruction from the program
- It is reached through the system-call table directly, with no change of mode
Show the answer
B. printf is a user-space library routine. Only the write call it eventually makes crosses into the kernel through a trap.
Why not A: printf is a library routine that executes in user mode.
Why not C: The shell is not involved in the trap that a library wrapper issues.
Why not D: Only the underlying write call goes through the table, with a mode change.
A program copies a 10 KB file with a 4 KB buffer. It opens the source and the destination, then loops with read and write until read returns 0, then closes both files. How many system calls does it make?
- 9
- 10
- 11
- 12
Show the answer
C. Opens 2, reads 4096, 4096, 2048 and 0 give 4, writes 3, and closes 2, for 11 in total. The last read that returns 0 still counts.
Why not A: This forgets the final read that returns 0 to signal end of file.
Why not B: This miscounts the loop and drops one of the reads or writes.
Why not D: This counts a write for the final empty read, but nothing is written then.