Jonathan Gardner jgardn at alumni.washington.edu
Mon Aug 26 20:52:47 CDT 2002

On Monday 26 August 2002 03:16 pm, Baker, Stephen M wrote:
> I'm looking for the correct exit command for the following situation:
> Program A coninuously checks environment conditions and runs Program B as
> necessary.
> Each time Program B runs, it spawns multiple instances of program C.
> Eventually, Programs B and C complete execution, modify the environment,
> and Program A again notices changes and restarts the cycle.
> I have the program catching signal interrupts for exit purposes, but I
> don't know whether to go with a kill 9, an exit(?), or what.
> What I want to do when exit is called is kill all instances of programs A
> and B, but not any occurances of program C.

If program A is persistent (for instance, it sleeps between checking, and 
doesn't need to be restarted each time to be checked), you can store program 
B's pid in a list.

Set up the beginning of your program to say:

$SIG{TERM} = sub {
	map {kill "TERM", $_} @pids;

You'll also need to keep the list of pids current, but that is easily handled 
through "waitpid" or just "wait", and $SIG{CHLD}. Look in the camel book for 
more info on this.

The same thing we do with A and B applies for B and C as well.

If A is not persistent, you will have to store it in a file or make sure B is 
done before you exit.

Jonathan Gardner
jgardn at alumni.washington.edu

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

More information about the spug-list mailing list