The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to know a executable has finished his task electroon Shell Programming and Scripting 4 01-04-2008 02:12 AM
** Finished ** Syncid.rc syndex Shell Programming and Scripting 1 07-10-2007 10:18 AM
background job finished notification nkeller UNIX for Dummies Questions & Answers 4 03-08-2007 12:41 PM
Has my script finished? Bab00shka UNIX for Dummies Questions & Answers 5 07-23-2002 09:39 AM
Finding Out When A Process Has Finished? 1cuervo UNIX for Advanced & Expert Users 5 11-02-2001 05:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-24-2008
Carla Carla is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
How do I know all processes are finished?

Hi all,

I am writing a C shell script that starts a program. The program forks of several child processes. Only when all child processes are done, I want to archive my log files. Below is what I have so far, but unfortunately it doesn't work.

MyProgram

if (-e processes.txt) then
rm processes.txt
endif
ps -C MyProgram | grep MyProgram > processes.txt

while (-s processes.txt)
rm processes.txt
ps -C MyProgram | grep MyProgram > processes.txt

rm processes.txt

# start archiving log files

The while loop is done twice and than the archiving starts, while one of the child processes is still running. Does anyone know what I am doing wrong or does anyone have any other suggestion on how to do this?
Thanks a lot.
  #2 (permalink)  
Old 04-24-2008
curleb curleb is offline
Registered User
  
 

Join Date: Mar 2008
Location: Here, in my Ivory Tower...
Posts: 68
Your best bet is to have each fork generate and then remove a lockfile of their own upon start and exit. The parent process or some other process can then monitor these for status and run the archive process when all of the lockfiles are gone. Something like while [ -e $lockfdir/$lockfile ] or sleep then check an ls command's $? for 0 would probably work ...
  #3 (permalink)  
Old 04-28-2008
Carla Carla is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
I just found it that my solution works when I use goto's instead of while.
Does anyone know why that is?
Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0