I have a program that forks, then does a system call to start up
another process. For example:
pid = fork();
if ( pid == 0 ) /* in child */
{
system("xterm -e runprog");
exit (0);
}
So, I get 4 relevant pids (not counting my original pid):
1. The pid of the forked copy of my program
2. The sh (shell) created by the "system" call
3. The call to the "xterm" part of the system call
4. The program "runprog" executed by the "xterm" command.
Now, the only pid that I can find easily is pid #1 (from the "fork").
But, when I exit my original program, I want to kill all the
sub-processes and forked processes, i.e. #2, #3, #4. What is the best
and cleanest way of determining forked children and their subsequent
"children"?
I've thought of using "popen" and sending a "getpid()" and/or
"getppid()" through the pipe, but I haven't been able to make it work.
Does anyone have other ideas? Or help me expand on this one?
I'd be very grateful for any help!
-- Anita --
--
---------------------------------------------/-----------------------------
| Anita Hsiung | E<**\R. _____ * |.Q \ U . \ K . |\ . . |
| BBN Canoga Park, USA |. \/. \--- H --+----\ .* /___/ ** V V . |