use strict; use warnings; use IPC::Run qw(run); my($wtr, $rdr, $err); my @cmd = qw(script); my $pid = fork; my $timvariable = 7; unless($pid) { setpgrp; run \@cmd, '>>', "out.txt", '2>>', "err.txt"; } print "Child process id:$pid\n"; for(my $i =0;$i <= $timvariable ; $i++) { sleep(1); print "Parent is waiting to obtain the file which was created by child process\n"; } kill 9,"-$pid"; kill 9,"$pid";