Consider the following example. There I used setpgrp to make the process group and process group id as forked process
check.plscript file:print "process id: $$\n"; my $pid = fork; my $FH; unless($pid){ setpgrp; exec('script'); } print "Child process id is: $pid\n"; while(1) {sleep(5)}
use POSIX; while(1) { sleep(1); print "I am running\n"; my $pid = fork; unless($pid) { while(1) { sleep(2); print "I am child and I'am running\n"; } } }
In the script file once again fork the process and printing the line
From another terminal using kill -9 <Negative number of the child process id> command kill all the process belongs to this process group
The child process is running as a defunct process but the parent process is alive
Refer the ps command output
643 15141 9607 0 18:14 pts/1 00:00:00 perl check.pl
643 15142 15141 0 18:14 pts/1 00:00:00 script <defunct>
How could I avoid this problem
Also I need to redirect the script command output and error into one file . How can I achieve it?
In reply to Re^6: Obtain the child process id in perl
by Anonymous Monk
in thread Obtain the child process id in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |