On a Linux machine:
ps -ef --forest | head -40andpstree -p | head -20— find PID 1 and your shell. Which process is the parent of your shell?- Run
sleep 300 &, thencat /proc/$!/status | head -12— reportState,PPid,Threads,VmRSSand explain each. - Make a zombie. Save and run this Python program (or write the C/Java equivalent):
While it sleeps, runimport os, time pid = os.fork() if pid == 0: os._exit(0) # child exits immediately time.sleep(60) # parent does NOT call wait()ps -o pid,ppid,stat,cmd -p <childpid>— what state do you see? What happens after the parent ends? - 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 withps -eLf | grep pythonortop -H -p <pid>. How many kernel threads (LWP) do you see, and why? nice -n 10 yes > /dev/null &thentop— what are theNIandPRvalues? Stop it withkill <pid>; which system call did thekillcommand use, and which signal is sent by default?
Report key output lines and explain them with this chapter's concepts.