LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl wait issue (http://www.linuxquestions.org/questions/programming-9/perl-wait-issue-908974/)

PMP 10-19-2011 10: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

Code:


END {
  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 07:43 AM

Quote:

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 08: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:
Code:

$? = 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
Code:

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


All times are GMT -5. The time now is 12:39 AM.