All notes

System calls, processes, threads, inter-process communication

GATE CS75 min read

Free preview: 29% of the note

Operating system interface and system calls

Definition. A system call is a controlled entry from a user program into a kernel service, such as file access, process creation, or communication. The call usually switches execution mode, validates arguments and permissions, performs the service, then returns a result or error code.

Example. A program calls read(fd,buffer,n) to request bytes from an open file descriptor.

Exam point. A library function may wrap one or more system calls; the two terms are not interchangeable.

Solved examples

Example 1 — classify operations. Classify opening a file, adding two integers, and asking the kernel for a process ID.

  1. Opening a file requests kernel-managed I/O and uses a system call.
  2. Integer addition executes as a user-mode instruction.
  3. Obtaining a process ID may invoke a system call or a library wrapper that does so.
  4. Only kernel-mediated services require system-call entry.

Example 2 — mode switch. A user process calls read and the device is not ready.

  1. The CPU traps into kernel mode to validate the descriptor and request I/O.
  2. If the call must wait, the OS blocks the process and schedules another ready process.
  3. Device completion later makes the caller ready; it resumes and returns a result.
  4. A system call can cause blocking and a context switch, but need not do so in every implementation.

Process concept and process states

Definition. A process is a program in execution together with its address space, resources, and execution state. A process control block (PCB) stores information needed to pause and resume it. Common states are new, ready, running, blocked/waiting, and terminated.

Example. A running process that requests disk input moves to blocked; on I/O completion it moves to ready.

Exam point. Ready means eligible for CPU; blocked means waiting for an event and not eligible yet.

Solved examples

Example 1 — state transitions. Trace a process that starts, receives CPU, requests I/O, completes I/O, runs again, and exits.

  1. Creation places it in new, then ready.
  2. Dispatch changes ready→running.
  3. I/O request changes running→blocked.
  4. I/O completion changes blocked→ready; later dispatch changes ready→running.
  5. Exit changes running→terminated.
  6. The I/O completion does not directly make it running; the scheduler must dispatch it.

Example 2 — preemption. A time quantum expires while process P is running.

  1. P has not finished and is not waiting for I/O.
  2. The timer interrupt returns control to the OS.
  3. P is moved from running to ready; another process may be dispatched.
  4. This is preemption, not blocking.

Process control block and context switch

Definition. A PCB can contain process state, program counter, registers, scheduling information, memory-management data, accounting, and I/O status. A context switch saves the outgoing execution state and restores the incoming process state; it is overhead and does not perform useful work for either process.

Example. Switching from P to Q saves P's program counter and registers and loads Q's.

Exam point. Address-space changes may require translation-cache handling; exact cost depends on hardware and OS design.

Solved examples

Example 1 — context switch count. P runs, is preempted for Q, and later resumes. How many switches between P and Q occur?

  1. First switch: P→Q.
  2. Second switch: Q→P.
  3. Two process context switches occur, excluding any kernel entry bookkeeping not counted as a process switch.

Example 2 — distinguish trap and switch. A process performs a system call that returns immediately without blocking.

  1. There is a user-to-kernel mode transition.
  2. The same process may continue after the kernel returns.
  3. A mode switch occurs, but a process context switch is not required.

Process creation and termination

Definition. A process can create children and form a process tree. Creation may allocate a PCB and address space or use copy-on-write sharing; termination releases resources and records an exit status for a parent or system service. Parent/child behavior depends on the OS API.

Example. A shell creates a child process to execute a command and waits for its completion.

Exam point. A child may inherit open descriptors or environment information, but these details are API-specific.

Solved examples

Example 1 — fork return values. In a Unix-like model, fork creates a child. What value is returned in each process?

  1. The parent receives the child's process identifier, assumed positive.
  2. The child receives zero.
  3. Failure returns an error in the parent and creates no child.
  4. After success, both processes continue from the instruction after fork with different return values.

Example 2 — wait. Parent creates child C and calls wait.

  1. If C is still running, parent may block.
  2. When C terminates, the kernel reports its status and releases wait state.
  3. Parent becomes ready and later resumes.
  4. wait synchronizes parent with child termination; it is not CPU busy-waiting by definition.

Threads and multithreading

Definition. A thread is an execution sequence with its own program counter, register set, and stack. Threads in one process share code, data, and many process resources. Kernel threads are scheduled by the OS; user threads are managed by a runtime, with mapping models determining blocking and parallelism.

Example. Two threads in one process can update shared variable x while using separate stacks.

Exam point. Shared address space allows communication but creates synchronization obligations.

Solved examples

Example 1 — private versus shared. Process has threads T1 and T2; T1 changes a local stack variable and a global variable.

You have read the free 29% of this note

Sign in with Google to keep reading. It is free, takes one tap, and you also get:

  • 6 practice questions from this note
  • Every note in full, plus the PDF library
  • Official past papers as timed tests, with explanations
  • An AI tutor for doubts, in Hindi or English
  • Your progress, mistakes and study plan saved on every device
Continue reading, free