Berger, Daniel
7/13/2006 2:32:00 PM
Douglas McNaught wrote:
> "Erich Lin" <dmatrix00d@gmail.com> writes:
>
>> I meant taht I would call a parent process to open, which is some
>> program. And that program can POTENTIALLY open up other children
>> processes. The thing is I only have the pid of the parent, and when
>> I kill the parent, only the parent will die. Is there a way that I
>> can kill the parent and the children that it sprang (which I did not
>> provide the exec code for since they were provided by the parent
>> itself that I did not code).
>
> I don't think you can do this in the general case on Unix unless you
> use ptrace(), which you really don't want to do. A process can only
> know its immediate children. If you call setsid() in the child after
> the fork(), and if the program you exec() doesn't do any
> session-management calls (setsid(), setpgrp()) itself, then it will
> probably work to call 'kill(-N, SIGTERM)' where N is the PID of your
> child process (which is the parent of the other processes). If the
> program you're calling does setsid() or setpgrp() on its own, you will
> probably lose.
>
> This session and process group stuff will bend your brain--it's not
> simple at all. I have no idea whether you can do what you're looking
> for on Windows, though you might be able to using the POSIX
> extensions.
>
> -Doug
>
Note that there is Process.sigsend if you have the proc-wait3 package:
require 'proc/wait3'
Process.sigsend(Process::P_PGID, gid, 'TERM')
This will not work on MS Windows, however. For Windows you'll have to use
sys-proctable and manually check for the ppid member value.
Regards,
Dan
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.