next up previous
Next: Crash the stacks Up: Assignment 4: Multi-threaded Programs Previous: Tug of war!

Children outlive their parents

When you run your program, you have probably noticed that the shell returns (prints a new prompt) as soon as the parent thread quits, even if the child is still running. If you put the child into an infinite loop, it will run forever and you will not be able to kill it from the shell using Control-C.

1.
Make the child execute an infinite loop.
2.
Run sproc. When the prompt returns, run ps. You will see something like this:

   PID TTY      TIME COMD
  2676 ttyq2    0:01 csh
  2675 ttyq2    0:02 rlogind
 19461 ttyq2    0:00 ps
 18889 ttyq2    0:24 emacs
 19460 ttyq2    0:00 sproc

3.
This indicates that the pid of the child is 19460. You can kill it from the command line by typing kill 19460.



Allen B. Downey
3/5/1998