LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-19-2011, 09:54 AM   #1
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
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 ?
 
Old 10-20-2011, 06:43 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,683

Rep: Reputation: 487Reputation: 487Reputation: 487Reputation: 487Reputation: 487
Quote:
Originally Posted by PMP View Post
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.
 
Old 10-20-2011, 07:05 AM   #3
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
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) {}
 
  


Reply

Tags
perl, status, wait


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Read from stdin in perl, do not wait for EOF smeezekitty Programming 1 04-28-2010 03:17 PM
Perl datescript Issue, missing perl module? stefaandk Programming 5 02-19-2006 10:55 PM
Perl: Wait for ssh connection to close kenneho Programming 9 10-29-2005 09:19 AM
perl with BerkeleyDB issue? Xstack Programming 0 06-03-2005 07:09 PM
perl issue moonloader Slackware 2 03-27-2004 01:07 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration