[Sort of ot]: Perl Fork and Exec...

Scholz Matthew scholzmb at yahoo.com
Fri Jan 10 15:13:54 PST 2003


So, I wrote a program which contains this little
snippet of code:

##
$pid = fork();
	if($pid == 0){
		exec("$command") or die;
		exit;
	}
##

now, later on, the program tries to kill the process
returned from $pid and depending on the signal I send
one of two things happens.  Either NOTHING, or it
kills the /bin/sh call which is starting these
processes, but not the acutal processes.

Allow me to explain:

server.pl (master program) starts several children. 
when it runs, a `ps -ef` of the related programs looks
like this:
root     13655  9592  0 15:10 pts/0    00:00:00
/usr/bin/perl -w ./server.pl
root     13657 13655  0 15:10 pts/0    00:00:00 sh -c
tail -f /users/mscholz/server/server.pl>/dev/tty10
root     13658 13655  0 15:10 pts/0    00:00:00 sh -c
java -cp
/net/www/cgi-bin/biopc:/net/www/cgi-bin/biopc/mm.mysql-2.0.14-b
root     13659 13657  0 15:10 pts/0    00:00:00 tail
-f /users/mscholz/server/server.pl
root     13660 13658  8 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13690 13660  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13691 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13692 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13693 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13694 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13695 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13696 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne
root     13697 13690  0 15:10 pts/0    00:00:00
/usr/java/jdk1.3.1/bin/i386/native_threads/java -cp
/net/www/cgi-bin/biopc:/ne

now, if I run a kill on the sh scripts, the sub
processes (in this case java, and tail) get adopted by
init (pid 1).  I CANNOT figure out how to get around
this using perl, without running a ps -ef into memory,
and greping for process IDs.  

any help, suggestions or spiritual guidance would be
appreciated.

Matthew Scholz the very frustrated.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


More information about the Linux mailing list