[Israel.pm] $SIG{CHLD}

Eitan Schuler Eitan.schuler at exlibris.co.il
Wed Nov 3 23:18:14 PST 2004


People,
I would like to run an external program (with system) in a child process. If
the time elapsed is more than 5 seconds I pretend that the child process is
stuck and I would like to kill it from the parent. I wrote this code:

	$SIG{CHLD} = sub {wait ()};

	$pid = fork ();
	if ($pid == 0){
	    system "csh -f external_program";
	}
	else{
	    if ($pid > 0){
	        sleep 5;
	        kill 9 => $pid;
	        exit;
	    }else {
	        die "cannot fork";
	    }
	}

This works nice, the 'kill' kills the child perl process. BUT the "csh -f "
becomes a zombie, because I killed it's parent (of course).
I would like to kill it as well, but I don't know it's pid.
Anybody has an idea on
	- how to get the "csh -f" 's pid
	- other solution for the problem
?

Thanks
Eitan




More information about the Perl mailing list