T.S.Ravi Shankar wrote:
> Dear all :
> 
> I see these lines in a perl program :
> 
> $pif = fork;
> if($pid == 0) {
>   exec("hpxy  -s   xxx.abc");
> }else{
>   $pid1=wait;
> }
> 
> I could understand that the fork is needed here to get into the child
> process "hpxy" !! What is the need for the "wait" here ??  When will
> the "else" loop be entered ?? 

After fork() there are two processes, parent and child. fork returns 0 to
the child, and the child's pid to the parent. So the "if" part is handling
the child, while the "else" part is handling the parent.

Basically, the child is exec()'ing a new program, while the parent is
calling wait(), which waits for the child to terminate.

The lines above are essentially equivalent to:

   system("hpxy -s xxx.abc");

Unless there's something else going on in the program that we're not seeing,
system() should be used instead of the code above, IMO.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to