$childPid = open SON, "-|"; sub sigtrap() { print "\n"; print("------ Killing all childrens then exeting ... ------\n"); if(defined($childPid) && ! ($childPid == 0)){ killfam 'KILL', ($childPid); } print "\n"; print "Exiting ... \n"; exit(1); } if ($childPid) { #parent system("while true; do echo aabbcc >> $temp_file; sleep 2; done"); }else { print "[$$]: Child...\n"; system("tail -f $temp_file >> $file &"); exit(0); }