in reply to How do you get PID of a program called using system call?

Thank you all for your reply, I found it very helpful. However, when I mention about having 4 system calls that resulted in 4 pids, I mean the following(having them runnning in background):
my $cmd = "process_file -c arg1 -d arg2"; for(1..40) { if(!WINDOWS) { system("$cmd > /dev/null &"); } else { system("sh -c \"$cmd > /tmp/null \"&"); } }
as you can see, the above code will gives me 4 processes running in the back ground, but I have no control over those pids

Replies are listed 'Best First'.
Re: Re: How do you get PID of a program called using system call?
by rob_au (Abbot) on Oct 09, 2001 at 06:55 UTC
    With this approach in mind, your best solution would be to iteration through the process table following execution of your system processes. Under *NIX, you would want to use Proc::ProcessTable (which I have written about before here). For Windows, you should take a look at either Win32::Process or Win32::ProcFarm.

    Even so, I still think that you would find the best solution from pre-forking within your script, rather than launching system processes and detaching yourself from the controlling tty. This pre-forking approach would give you greater control, without the need to extraneous loops and control structures, of your spawned processes.

     

    Ooohhh, Rob no beer function well without!