Re: problem with fork & wait

From: Smoot Carl-Mitchell (smoot_at_tic.com)
Date: 03/29/04


Date: Mon, 29 Mar 2004 13:45:16 -0700
To: beginners@perl.org

On Mon, 29 Mar 2004 18:38:48 +0530
"T.S. Ravi Shankar" <Ravi.Shankar@synopsys.com> wrote:

> At reaching a certain point in my perl program, I need to run a
> process( say XYZ ) using SYSTEM command. The result file that this
> process would produce will be result.<process_id>. I will have to
> wait until this result file is produced & then proceed extracting
> certain things from this file.
>
> I am implementing this as :
>
> foreach $check (@run) {
>
> $pid=fork;
> if($pid == 0) {
> exec("XYZ -a $check");
> }else{
> $pid1=wait;
> }

The above works, but it is equivalent to:

system("XYZ -a $check");

You should check the return value of system. A non-zero value means the
forked program returned a non-zero exit status which depending on what
you do with the output may or may not be an error.

-- 
Smoot Carl-Mitchell
Systems/Network Architect
email: smoot@tic.com
cell: +1 602 421 9005
home: +1 480 922 7313