- LPU MCA Semester 1
- CAP366
- 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.
| Term | Meaning |
|---|---|
| Zombie | Has terminated, but still occupies a process-table entry until the parent calls wait() |
| Orphan | Parent 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
Which Unix system call creates a new process by duplicating the calling process?
- fork()
- exec()
- wait()
- 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.
Which of the following is a feature of an orphan process?
- It is waiting for I/O
- It has no PCB
- Its parent has terminated while it is still running
- 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).