Skip to content

System Calls

Short Notes

The interface between a process and the Operating System.

Categories

  • Process Control: fork, exit, wait.
  • File Management: open, read, write, close.
  • Device Management: ioctl, read, write.
  • Information Maintenance: getpid, alarm.
  • Communication: pipe, shmget.

Key Theories & Formulas

1. Trap vs Interrupt

  • Trap (Software Interrupt): Generated by the process internally (e.g., system call, error like division by zero).
  • Interrupt (Hardware Interrupt): Generated by external devices.

Example Problems

Problem: Which system call is used to create a pipe?

  • Result: pipe().

Hardest GATE Questions

Topic: Return values of concurrent fork() and wait() Tricky Question (GATE 2014/2021): What is the sequence of outputs for nested fork() and wait()?

  • Analysis:
  • wait(NULL) blocks the parent until any child terminates.
  • waitpid(pid, ...) blocks for a specific child.
  • The "Trap": Understanding that fork() returns twice.
  • If fork() fails, it returns -1.
  • Hard Aspect: Mode switch vs Context switch.
  • A system call involves a Mode Switch (User to Kernel). It does not necessarily involve a Context Switch (Process to Process) unless the calling process blocks.
  • Complexity: Internal working of execve and how it handles open file descriptors

References