Based on the Linux Master 1 exam syllabusReport an error
& (background) · Ctrl+Z (stop) · jobs · bg · fg · nohup (survive logout).kill -9 has no effect on it, and it disappears only when you terminate or restart the parent.| Characteristic | Description |
|---|---|
| No controlling terminal | Not tied to any terminal, so it keeps running after logout |
| Resident in the background | Starts at boot and stays in memory until shutdown |
| Parent is usually PID 1 | Managed directly by systemd/init, or adopted by it |
| 'd' in the name | sshd, httpd, crond, rsyslogd, etc. |
| Mode | Behavior | Examples |
|---|---|---|
| Standalone | The daemon is always running and handles requests itself | httpd, sshd |
| Super-daemon | xinetd/inetd waits and launches a child daemon on request | old telnet, ftp |
The standalone mode responds quickly but always occupies memory. The super-daemon (xinetd) mode saves memory normally but responds slowly because it launches a new process for every request. The trade-off that frequently used services favor standalone while rarely used services favor super-daemon shows up on exams.
The word 'daemon' comes from the "spirit that helps invisibly" in Greek mythology. It originated at MIT's Project MAC, where background helper processes were called this. Its spelling differs from demon, and it carries the meaning of working quietly out of the user's sight.
& at the end of a command. The shell gives you the prompt back immediately, so you can keep working.sleep 100 # foreground: the prompt is stuck for 100 seconds
sleep 100 & # background: prompt returns at once, prints [1] 12345| Command/Key | Action |
|---|---|
& (after a command) | Run in the background from the start |
Ctrl+Z | Suspend (Stopped) the foreground job |
jobs | Show the current shell's job list and job numbers |
bg %1 | Resume stopped job 1 in the background |
fg %1 | Bring job 1 to the foreground |
nohup ... & | Run so that it survives logout |
sleep 200 # running...
# (press Ctrl+Z) → [1]+ Stopped sleep 200
jobs # [1]+ Stopped sleep 200
bg %1 # resume in the background → [1]+ sleep 200 &
fg %1 # back to the foreground
nohup ./long.sh & # keeps running after logout, output saved to nohup.out⚠️ Trap:
Ctrl+Zis not termination but a suspend (SIGSTOP, state T). Termination isCtrl+C(SIGINT). A stopped job must be revived withbg/fg, and if you just leave it and close the shell it may disappear. Also, with&alone the job may die when the shell exits because it receives SIGHUP, so to keep it alive after logout you must usenohuptogether with it.
Try it yourself: Run sleep 300, stop it with Ctrl+Z, and check with jobs that the state is Stopped. Resume it with bg %1 and the state changes to Running. Bring it back with fg %1 and terminate it with Ctrl+C, and it disappears completely. That is one full cycle of job control.
[shell process] --fork()--> [child (shell copy)] --exec("/bin/ls")--> [ls process]
PID 1000 PID 1500 PID 1500 (kept)
PPID 1000 PPID 1000
ls in the shell, the shell forks itself to make a child, that child becomes ls through exec, and it exits when it finishes running.wait() and then gives the prompt back.| System call | Role | PID change |
|---|---|---|
| fork() | Copy the process (create a child) | New PID created |
| exec() | Replace the current process with another program | PID kept |
| wait() | Parent waits for the child to terminate and reaps it | — |
| exit() | Terminate the process (return an exit code) | — |
exec does not create a new process. It leaves the current process's shell (PID) as is and swaps out only the contents (the executing code). That is why, if you type exec ls directly in a shell, the shell itself transforms into ls, and when ls finishes the shell terminates as well. Separating fork (copy) from exec (replace) is the elegance of Unix.
Thanks to the fork-exec separation, the shell can set up I/O redirection (>, <) or pipes (|) right after forking the child and before exec. If "copy and replace" had been bundled into one step, such flexible rearrangement of I/O would have been impossible. This design is the foundation of the Unix pipeline philosophy.
exit(), the kernel keeps its exit code for a while so that the parent can pick it up.wait() and collects the exit code, the child's traces vanish completely.wait(), the child is already dead but its exit code remains, leaving a trace in the process table → this is a zombie (defunct) process.| Item | Zombie process |
|---|---|
| State (STAT) | Z (or shown as <defunct>) |
| Memory | Almost none used (only the shell) |
| Cause | The parent doesn't collect the exit code with wait() |
| Danger | Occupies a PID slot — PIDs can be exhausted if many accumulate |
| Fix | Terminate/restart the parent process → the zombie is adopted by PID 1 and cleaned up |
ps aux | grep -w Z # find processes in zombie state
ps -ef | grep defunct # check zombies shown as defunctkill -9 (it is already dead).wait().⚠️ Trap: A zombie process uses almost no memory, but it occupies a PID slot. If a badly written program keeps churning out zombies, PIDs run out and the system can no longer create new processes. Trying to kill a zombie with
kill -9 zombiePIDis pointless — the target is the parent.
wait() → it is not harmful to the system.| Category | Zombie | Orphan |
|---|---|---|
| Child state | Dead (terminated) | Alive (running) |
| Parent state | Alive but not calling wait | Terminated first |
| PPID | Original parent | Changed to 1 (adopted) |
| Danger | Occupies a PID, a problem if it accumulates | Harmless (PID 1 reaps it normally) |
| Fix | Terminate/restart the parent | Resolved by automatic adoption |
The one-line key contrast — a zombie is a dead child + a parent that doesn't collect it (dangerous), an orphan is a living child + a dead parent (harmless, adopted by PID 1). Answer choices that swap the two are used as traps. Also memorize "Z state = zombie, shown as defunct".
Try it yourself: Run ps -ef and look at the processes whose PPID (third column) is 1. Daemons started at boot and adopted orphans all have PID 1 as their parent. You can confirm from the actual list how PID 1 acts as the guardian of every lost child.
Without the orphan adoption mechanism, a process run in the background like nohup ./job & would be left without anyone to reap it the moment the shell (its parent) exits, and would eventually become a zombie. Thanks to adoption by PID 1, we can safely run background jobs even after logging out.
& so you get the prompt back.jobs and refer to them by job number such as %1.Click a choice to reveal the answer and explanation.
Question 1
Which of the following statements about daemon processes is NOT correct?
Question 2
What is the result of pressing Ctrl+Z on a job running in the foreground?
Question 3
Which of the following statements about the fork-exec model for running a new program is correct?
Question 4
What is the most accurate cause of a zombie process?
Question 5
Which of the following is correct about orphan processes?
Question 6
What is the most correct way to remove a zombie process?
Question 7
Which command keeps a background job running after logout without being killed by SIGHUP?