I came across this need where I had to run one script which runs a Linux command continuously in a "while(1)" loop and another script which would capture the Process ID ( i.e. $$ in Perl context) and terminate it .