##################### # sub display # display a message using xmessage # execs the xmessage command using the "double-fork trick" to prevent zombies { my $msg = shift; my $child; my $buttons='Roger:0'; if($child = fork) { #running in parent warn("parent: pid $$ is waiting on child $child\n") if $debug; waitpid($child,0); # wait for first child warn("parent: pid $$ is returning from spawn()\n") if $debug; return; } else { # running in child -- fork again to protect against zombies if(0 != fork) { #running in zombie-protector parent warn("first child: pid $$ exiting now\n") if $debug; exit(0); } else { #running in zombie-protected child warn("second child: pid $$ is execing the command\n") if $debug; open(XMESS,"|xmessage -xrm 'xmessage*Title:Notify' -buttons '$buttons' -file -") || die("$prog: xmessage failed:$!\n"); (print XMESS $msg) || die("$prog: xmessage didn't work:$!\n"); exit(0); } } die("spawn: you're not supposed to run this.\n"); }