THINK FIRST·CODE LATER

← All labs

Linux in practice: processes, threads and zombies

Problem

On a Linux machine:

  1. ps -ef --forest | head -40 and pstree -p | head -20 — find PID 1 and your shell. Which process is the parent of your shell?
  2. Run sleep 300 &, then cat /proc/$!/status | head -12 — report State, PPid, Threads, VmRSS and explain each.
  3. Make a zombie. Save and run this Python program (or write the C/Java equivalent):
    import os, time
    pid = os.fork()
    if pid == 0:
        os._exit(0)          # child exits immediately
    time.sleep(60)           # parent does NOT call wait()
    
    While it sleeps, run ps -o pid,ppid,stat,cmd -p <childpid> — what state do you see? What happens after the parent ends?
  4. Run a multithreaded program (e.g., python3 -c "import threading,time; [threading.Thread(target=time.sleep,args=(60,)).start() for _ in range(5)]") and inspect it with ps -eLf | grep python or top -H -p <pid>. How many kernel threads (LWP) do you see, and why?
  5. nice -n 10 yes > /dev/null & then top — what are the NI and PR values? Stop it with kill <pid>; which system call did the kill command use, and which signal is sent by default?

Report key output lines and explain them with this chapter's concepts.

Work it out on paper, in a document or here, then compare with the model answer. Your answer stays in your browser — it is never sent to or stored on the server.