1. University MCA (AI/ML) Semester 1
  2. CAP366
  3. Unit 2

CAP366 · Unit 2: Process

Operations on processes: creation and termination

14 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 3, Apply

After a Linux fork(), the parent and child initially share their data pages marked copy-on-write. When is a page actually copied?

  1. Immediately for every page at the moment of fork()
  2. Only when the child process terminates
  3. Whenever either process reads it
  4. When either process first writes to it
Show the answer

D. Copy-on-write delays copying until a write happens, so fork() is cheap and pages that are only read are never duplicated.

Why not A: Copying every page at fork() is exactly what copy-on-write avoids.

Why not B: Termination frees pages; it does not copy them.

Why not C: Reads can share the same page safely, so no copy is needed.

Question 2 · Tier 2, Understand

On Windows, which API call creates a new process with its own address space and loads a program into it?

  1. CreateProcess()
  2. CreateThread()
  3. ExitProcess()
  4. fork()
Show the answer

A. Windows uses CreateProcess() to create a process and load a program in one call. fork() is the UNIX/Linux call, CreateThread() adds a thread to an existing process and ExitProcess() terminates one.

Why not B: CreateThread() adds a thread inside an existing process.

Why not C: ExitProcess() ends a process.

Why not D: fork() is the UNIX and Linux call; Windows has no fork().