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%

Concept of a Process

Lesson 19 of 32 in the free Design of Unix Operating System notes on Siksha Sarovar, written by Rohit Jangra.

Introduction

A process is the fundamental unit of execution in UNIX. While a program is a static set of instructions stored on disk, a process is a program in execution — it has its own memory space, resources, and state.

What is a Process?

  • A process is an instance of a running program.
  • Every process has a unique Process ID (PID) — a positive integer assigned by the kernel.
  • Processes are created, executed, and eventually terminated.
  • UNIX is a multi-processing system — many processes can exist simultaneously.

Key Attributes of a Process

AttributeDescription
PIDUnique Process Identifier
PPIDParent Process ID (who created this process)
UIDUser ID of the owner
GIDGroup ID
PriorityScheduling priority
StateCurrent state (running, sleeping, etc.)
Program CounterAddress of the next instruction
MemoryText, data, and stack segments
Open FilesFile descriptors table

Process Creation — fork() and exec()

1. fork() — Creating a Child Process:

  • The fork() system call creates a new process (child) that is a copy of the calling process (parent).
  • The child process gets a new PID but inherits:
  • Copy of parent's memory (text, data, stack)
  • Copy of parent's open file descriptors
  • Parent's environment variables
  • fork() returns:
  • 0 to the child process.
  • Child's PID to the parent process.
  • -1 if the fork fails.

2. exec() — Replacing Process Image:

  • The exec() family of system calls replaces the current process image with a new program.
  • The PID remains the same, but the program code, data, and stack are replaced.
  • Variants: execl(), execv(), execle(), execve(), execlp(), execvp().

3. wait() — Parent Waits for Child:

  • The parent calls wait() to suspend itself until the child process terminates.
  • Returns the child's exit status.

4. exit() — Process Termination:

  • A process calls exit() to terminate itself.
  • Resources are deallocated, but the process table entry remains until the parent calls wait().

Special Processes

ProcessPIDDescription
Swapper (sched)0Kernel process for memory management (swapping)
init1First user-space process, ancestor of all user processes
pagedaemon2Handles paging (in some UNIX variants)
  • init is the parent of all orphan processes. If a parent terminates before its child, the child is adopted by init.
  • A process whose parent has not yet called wait() after the child has exited is called a zombie process.

Process Hierarchy

               init (PID 1)
              /     |      \
         login    cron    sshd
          |                |
        bash             bash
       /    \
     ls     grep
  • All processes form a tree rooted at init (PID 1).
  • Each process (except init) has exactly one parent.

Summary

  • A process is a program in execution with its own PID, memory, and resources.
  • fork() creates a child process; exec() replaces the process image.
  • wait() lets the parent collect the child's exit status.
  • All processes descend from init (PID 1) in a tree hierarchy.