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
suspend a process superuser84 UNIX for Advanced & Expert Users 6 03-18-2008 06:36 PM
Suspend Cron job temprory pankajkrmishra Shell Programming and Scripting 4 08-14-2006 05:18 AM
suspend/restart a process in shell script daneensign Shell Programming and Scripting 1 02-13-2006 09:43 PM
Suspend to write file ust UNIX for Advanced & Expert Users 3 12-13-2005 01:56 AM
UNIX Process Suspend proton UNIX for Dummies Questions & Answers 3 02-13-2005 12:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-29-2005
Registered User
 

Join Date: May 2005
Posts: 4
Question suspend a process

Hello,

Two child processes work at the same time because they communicate one another. In KSH, does it exist a good way to suspend a parent process until one of the two child processes stops. It seems that the command 'wait' works well for one process but for two processes, it suspends the parent process until all the background child processes stop.
If a command or a C-code could return a status as well, that will be more better.


thanks

Last edited by piou78; 05-29-2005 at 10:57 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 05-31-2005
Registered User
 

Join Date: Nov 2003
Posts: 11
You can use pipes for this

So you have two child processes and one parent process.

Create a pipe and have a "write to pipe" in each of the child processes
as the last statement in the child process.

and you have only one "read from pipe" in the parent process. so whichever child completes first, it will write to the pipe and the parent process will finish the read immediately.
Reply With Quote
  #3  
Old 05-31-2005
Registered User
 

Join Date: May 2005
Posts: 40
How about using signal?
Would it be convenient that both child processes send a SIGUSR1 to the parent before end and that the parent has a sig handler which terminates itself?
Tom
Reply With Quote
  #4  
Old 06-01-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
#!/bin/ksh

start_first_child.sh &
start_second_child.sh &

while [ $(jobs | wc -l) -gt 0 ] ; do
sleep 1
done

exit 0

Hope this helps

bakunin
Reply With Quote
  #5  
Old 06-01-2005
Registered User
 

Join Date: May 2005
Posts: 4
Quote:
Originally Posted by ramkumar_gr
So you have two child processes and one parent process.

Create a pipe and have a "write to pipe" in each of the child processes
as the last statement in the child process.

and you have only one "read from pipe" in the parent process. so whichever child completes first, it will write to the pipe and the parent process will finish the read immediately.

Thanks for the reply but I don't undertand what you mean by "write to pipe" or "read from pipe". Could you give me a practical example, please?

Thanks
Reply With Quote
  #6  
Old 06-01-2005
Registered User
 

Join Date: May 2005
Posts: 4
Quote:
Originally Posted by bakunin
#!/bin/ksh

start_first_child.sh &
start_second_child.sh &

while [ $(jobs | wc -l) -gt 0 ] ; do
sleep 1
done

exit 0

Hope this helps

bakunin
Thanks for the reply. Do you know a good way to get the status of the stopped child process. In case of error, the other child process could become a zombi process (consequently, I'll do a 'kill -9' on it). Notice that I won't do it if the stopping is normal.
Reply With Quote
  #7  
Old 06-01-2005
Registered User
 

Join Date: May 2005
Posts: 4
Quote:
Originally Posted by ramkumar_gr
So you have two child processes and one parent process.

Create a pipe and have a "write to pipe" in each of the child processes
as the last statement in the child process.

and you have only one "read from pipe" in the parent process. so whichever child completes first, it will write to the pipe and the parent process will finish the read immediately.
Thanks for the reply. Could you give me a practical example, please?. Could I get the status of the stopped child process with this method?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:04 AM.


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

Content Relevant URLs by vBSEO 3.2.0