Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>On Mac OS X 10.8.4, I created a program <code>zombie</code> from <code>zombie.c</code>:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;unistd.h&gt; int main(void) { pid_t pid; if ((pid = fork()) &gt;= 0) { if (pid == 0) { printf("%d: committing suicide (parent %d)\n", (int)getpid(), (int)getppid()); exit(0); } else { printf("%d: going to sleep for a while - child %d might die while I snooze\n", (int)getpid(), (int)pid); sleep(30); printf("%d: awake\n", (int)getpid()); } } return 0; } </code></pre> <p>When I ran it in one terminal window, the output was:</p> <pre><code>$ ./zombie 2443: going to sleep for a while - child 2444 might die while I snooze 2444: committing suicide (parent 2443) 2443: awake $ </code></pre> <p>In another terminal window, running <code>ps -f</code> produced:</p> <pre><code> UID PID PPID C STIME TTY TIME CMD 503 260 249 0 12:42PM ttys004 0:00.08 -bash 503 2443 260 0 5:11PM ttys004 0:00.00 ./zombie 503 2444 2443 0 5:11PM ttys004 0:00.00 (zombie) </code></pre> <p>The parenthesize <code>(zombie)</code> is the defunct process, and the name in parentheses is the original name of the process. When I copied the program to <code>living-dead</code>, the corresponding output was:</p> <pre><code> UID PID PPID C STIME TTY TIME CMD 503 260 249 0 12:42PM ttys004 0:00.09 -bash 503 2454 260 0 5:13PM ttys004 0:00.00 ./living-dead 503 2455 2454 0 5:13PM ttys004 0:00.00 (living-dead) </code></pre> <p>(On most systems, the defunct process is marked as <code>&lt;defunct&gt;</code> or something similar.)</p> <p>Clearly, the value in the <code>PPID</code> column identifies the parent process of the zombie, and the various process IDs match the output from the programs themselves.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload