-   Programming (
-   -   Perl wait issue (

PMP 10-19-2011 09:54 AM

Perl wait issue
I have a perl module in which I am trying to do some clean up activity in the END block. But prior to do this cleanup activity, I would like to wait for all the child(ren) of the process using this Module.

So I did something like


  my $pid = wait;
  #### Do the clean up stuff here

The issue I am facing here is that call to wait is setting up the status var ($?) to -1 in case there are no child of the current process. Which is in line with the definition of wait in man 2.

Is there a way I can ignore this setting of $? by wait ?

NevemTeve 10-20-2011 06:43 AM


Originally Posted by PMP (Post 4502564)
Is there a way I can ignore this setting of $?

It is very easy to ignore the value of a variable... or I don't understand your question.

SecretCode 10-20-2011 07:05 AM

I'm not sure I understand the need to ignore $? either. You can just reassign it to give the exit code you want:

$? = 0;
But I'm concerned about the wait logic: could you have more than one child process? wait will return when any child process ends - and in other cases as well. You probably want something more like

while (wait() != -1) {}

All times are GMT -5. The time now is 11:30 PM.