The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 08:22 PM
about child process compbug UNIX for Dummies Questions & Answers 12 03-22-2006 03:55 PM
gdb to child process shriashishpatil UNIX for Advanced & Expert Users 4 12-12-2005 03:57 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 01:41 PM
Child Process PID skannan High Level Programming 2 06-10-2002 04:54 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2005
Registered User
 

Join Date: Oct 2005
Posts: 84
How to Join with child process?

Java and perl have a join feature that allows the main thread to block until a child thread is finished.

Is there a similar feature in (1) bash and (2) perl that will allow the main process to block until the child process is complete?

Thanks,
Siegfried
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-14-2005
Registered User
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
in bash at least it is "wait"
You can wait for jobs, pids or all children.

Perl no doubt has something similar
Reply With Quote
  #3 (permalink)  
Old 10-14-2005
Registered User
 

Join Date: Oct 2005
Posts: 84
How to wait on multiple child processes?

Let us say I want to create five child processes while the parent process waits until they are all done.
(1) Normally I create a child process with the "&". How do I get the pid? Do I have to parse the "ps" command with perl or awk?
(2) How do I specify multiple child processes? I tried "info wait" and "man wait" with no luck. I also tried "info bash" and "man bash" and still no luck. However, I see that my distro does implement wait. Apparently it takes a single integer.

I tried "sleep 40&" and "sleep 30&" and "ps" and "wait 6088 5966" and that almost worked. It came back and said "pid 5956 is not a child of this shell after waiting for 6088". I'm checking my work. wait wants the first column of ps labeled "PID", correct?

Sieg
Reply With Quote
  #4 (permalink)  
Old 10-14-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Quote:
Originally Posted by siegfried
Let us say I want to create five child processes while the parent process waits until they are all done.
(1) Normally I create a child process with the "&". How do I get the pid? Do I have to parse the "ps" command with perl or awk?
foo &
fooPID="${!}"
echo "foo's pid -> [${fooPID}]"

Quote:
Originally Posted by siegfried
(2) How do I specify multiple child processes? I tried "info wait" and "man wait" with no luck. I also tried "info bash" and "man bash" and still no luck. However, I see that my distro does implement wait. Apparently it takes a single integer.

I tried "sleep 40&" and "sleep 30&" and "ps" and "wait 6088 5966" and that almost worked. It came back and said "pid 5956 is not a child of this shell after waiting for 6088". I'm checking my work. wait wants the first column of ps labeled "PID", correct?

Sieg
correct. Get the pid's of your background processes as outlined above and pass them to 'wait'.
Reply With Quote
  #5 (permalink)  
Old 10-15-2005
Registered User
 

Join Date: Oct 2005
Posts: 84
How to wait for logical "OR"

Since my info/man pages are incomplete, I am assuming wait implements a logical "AND" allowing my parent process to sleep until all the children have died.

(1) How would I implement an "OR" wait where the parent waits for the first child to die, examine the return status code of that child, and possibly spawn a new child to take its place?

The children will all be running perl.

(2a) I've tried writing synchronous perl children use various integer values for exit function, but I cannot figure out how to detect the exit values in bash. How is this done for a synchronous child?

(2b) How do I detect the return status code for an asynchronous child when the parent is blocking on multiple children wait for the first to die?

Thanks much!
Siegfried
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0