kill(-child_pid, SIGKILL);
Otherwise, there's no automatic way to do it.
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
> If the child is a process group leader, you can do
> kill(-child_pid, SIGKILL);
> Otherwise, there's no automatic way to do it.
> --
> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the
w> How can I set the child to process group leader?
In my server program I do this:
fork()
then, in the child:
setpgrp()
execl() the child, which is a script
The script does an exec of pppd
To kill pppd, the server knows what the original child pid is, so it runs
another script, passing the original child pid as an argument. This
second "kill" script then calls:
/bin/kill -s SIGTERM -${1}
Whether this is correct or not, I don't know. I discovered the concept of
process groups when killing pppd appeared to kill the server as well.
Alan
(If replying by mail, change scatology to AC2)
w> How can I set the child to process group leader?
Alan> In my server program I do this:
Alan> fork()
Alan> then, in the child:
Alan> setpgrp()
see also the job control example in the FAQ.
setpgrp() is a bit non-portable because there were two incompatible
versions: the BSD version with two arguments (equivalent to setpgid)
and the SysV version with no arguments (equivalent to setpgid(0,0)).
The FAQ example calls setpgid() for the child in both parent and child
processes; that's necessary to avoid race conditions in some cases
(i.e. if the parent needs to make some use of the pgid before the
child process has reached the setpgid() call). The child has to do the
call too because the parent can't change the child's pgrp after the
child has performed an exec*().
--
Andrew.
comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
or <URL: http://www.whitefang.com/unix/>
1. how to kill a child process that runs other children processes
here's my problem: i am spawning a child process using spawnv in c,
launching an executable and passing some arguments to it. then, in another
thread i wait for a certain amount of time and if the first thread reaches a
certain threshold, i kill the spawned child process. this works total okay
but because the executable that i run in the spawned process launches some
other programs on its own, they continue to run regardless of the fact that
i killed their parent process. to make things clear: i spawn process A.
process A is an executable and i don't have its source. process A launches
a bunch of other processes B, C and D ( they are also separate executables
w/o source code ). when i kill process A, it dies but processes B, C and D
continue to run.
so, the question is: is there a way to kill the children of a child process
( i.e. grandchildren ) without actually knowing their pids explicitly, i.e.
can i say to a process "die and kill all your children, too" *without*
modifying the code for that child process?
thanx in advance...
2. /dev/dsp broken on 1.1.31-35???
3. Getting a child and child's child process-id
6. How can kill all child processes without killing parent process ?
7. RH6 Linux Router Craps Out?!
8. smail failed to reap child process: No child processes
9. killing a shell script is not killing child processes
10. Can a process kill its child if it's killed -9
11. Parent process also terminating after killing child process in SIGINT