Killing children

Killing children

Post by Jonathan I. Kame » Thu, 02 Apr 1992 06:01:53




|> I have a program that forks a child and wants to kill it after a certain
|> time (this is a command line argument to the program).  The problem is
|> that the child itself starts up other children and when I try to kill
|> the first child from the parent, the other children continue to run.
|> How can I kill a process and all of its children from within my program?

You should have the child put itself into a new process group with setpgrp(),
but NOT have the grandchildren do so.  Then, you can use killpg() (on some
systems, the functionality of killpg() is provided with kill(); check your man
pages) to kill the child's process group, which will make all of the
grandchildren go away as well.

--

MIT Information Systems/Athena              Moderator, news.answers
    (Send correspondence related to the news.answers newsgroup
        {and ONLY correspondence related to the newsgroup}