1. LPU MCA Semester 1
  2. CAP366
  3. Unit 2

CAP366 · Unit 2: Process

Operations on processes: creation and termination

11 practice questions · in the MTE and ETE syllabus

Key points

  • fork returns 0 in child, child PID in parent
  • n unconditional forks give 2^n processes
  • Zombie: finished, awaiting wait()
  • Orphan: parent gone, adopted by init

A parent creates children with fork(). The child is a copy of the parent; fork returns 0 in the child, the child's PID in the parent, and -1 on error. The child may then call exec() to load another program, and the parent may wait() for it. A process ends with exit().

Counting processes: n unconditional sequential forks give 2^n processes in total (2^n - 1 children). Example: fork(); fork(); fork(); gives 8 processes. With a condition, trace each branch: if (fork()==0) fork(); fork(); gives 4 + 2 = 6 processes.

TermMeaning
ZombieHas terminated, but still occupies a process-table entry until the parent calls wait()
OrphanParent exited while it still runs; adopted by init

Exam pitfall: a zombie is finished and uses no CPU; it cannot be killed by a signal because it is already dead. An orphan is still running, and the two terms are often swapped.

Try two questions

Question 1 · Tier 1, Recall

Which Unix system call creates a new process by duplicating the calling process?

  1. fork()
  2. exec()
  3. wait()
  4. exit()
Show the answer

A. fork() creates a child that is a copy of the parent. exec() is usually called afterwards to load a different program.

Why not B: exec replaces the current program image and creates no new process.

Why not C: wait only makes the parent block until a child terminates.

Why not D: exit terminates the calling process.

Question 2 · Tier 2, Understand

Which of the following is a feature of an orphan process?

  1. It is waiting for I/O
  2. It has no PCB
  3. Its parent has terminated while it is still running
  4. It has finished but its parent has not yet read its exit status
Show the answer

C. A zombie has finished but is still in the process table awaiting wait() by the parent; an orphan has lost its parent (adopted by init).