Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Operations on Processes

Lesson 10 of 31 in the free Operating System & Linux Programming notes on Siksha Sarovar, written by Rohit Jangra.

Creating Processes — The fork/exec Model

In Unix, a process is created by an existing process calling fork(). The new process is an almost-exact copy of the parent. To run a different program the child then calls one of the exec family of system calls, which replaces its memory image.

Why fork+exec?

Splitting creation (fork) from program-loading (exec) lets the parent set up file descriptors, environment variables, and pipes for the child before the new program starts. This is how shells implement <, >, and | redirection.

Process Termination

A process ends by calling exit(status). The kernel:

  1. Closes all open file descriptors.
  2. Releases memory.
  3. Keeps a small zombie PCB until the parent calls wait/waitpid to collect the exit status.

If a parent dies before its children, the orphans are reparented to init (PID 1) which immediately reaps them.

Cooperating vs Independent Processes

  • Independent — cannot affect each other.
  • Cooperating — share data and need synchronization (Unit 2 later).

Inter-process Communication (IPC) Mechanisms

MechanismDescription
PipesUnidirectional byte stream between related processes (`lswc`).
Named pipes (FIFOs)Pipes with a filesystem name.
SignalsAsynchronous notifications (SIGINT, SIGTERM).
Shared memoryCommon memory segment mapped into multiple processes.
Message queuesKernel-managed queues of messages.
SocketsBidirectional, work over network.

Worked C Example

The code in the snippet below forks a child that prints "hello" while the parent waits for it.

Process Tree

Every process except init has a parent. The whole system is a tree visible via pstree.

Summary

  • fork duplicates a process; exec replaces its image; wait reaps the child.
  • A child returns 0 from fork; the parent gets the child's PID.
  • Zombies and orphans are normal transient states cleaned up by init.