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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to wait for the subprocess to finish in tcl nathgopi214 Shell Programming and Scripting 1 03-26-2008 09:40 AM
how do i finish this last one.. newby2 UNIX for Dummies Questions & Answers 2 01-18-2008 11:52 AM
wait for 5 seconds in shell script gopsman Shell Programming and Scripting 2 08-30-2007 05:47 AM
Need to execute 2 scripts, wait, execute 2 more wait, till end of file halo98 Shell Programming and Scripting 1 08-01-2006 04:42 PM
wait in shell scripts Vinaya Shell Programming and Scripting 1 09-23-2004 08:29 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 01-17-2005
superdelic superdelic is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 8
How can I wait for PID to finish in another shell

Have a need to schedule programs that can run after other programs are completed. Here's the catch:

1) The list of programs will not always be the same (kind of a plug-n-play deal)
2) The invoking shell may not be the same as the shell of the program being waited on

In other words, I need to be able to wait on PID's from other shells in the same Unix box. I've looked through Unix in a Nutshell & Power Tools and found nothing.

Any advice?
  #2 (permalink)  
Old 01-17-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Just loop checking to see if the process is still running. If so, sleep for ten seconds and loop again. If not continue.
  #3 (permalink)  
Old 01-17-2005
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
This is a script I wrote a long time ago and have been using since (not sure how widespread pgrep is, but this works in Solaris).

Code:
#!/bin/bash

# Variables
PROCESS=""      # This is what you want to page on
MAILTO=""         # Space delmited list of email addresses
HOSTNAME=`hostname`
A=1

 # Processing
until [ ${A} -eq 2 ]; do
   pgrep -f "${PROCESS}" >/dev/null 2>&1
   if [ $? -eq 0 ]; then
        sleep 300
        else sleep 30
        pgrep -f "${PROCESS}" >/dev/null 2>&1
        FLAG=$?
        if [ ${FLAG} ! -eq 0 ]
           then echo "$PROCESS is no longer running on ${HOSTNAME}" | mailx -s "
${PROCESS}" ${MAILTO}
           A=2
           exit 0
        fi
   fi
done
It checks that a process is running every 5 minutes. If it goes away, it waits 30 seconds and checks one last time to make sure.

I know this isn't exactly what you are looking for, but you should be able to modify it to work (sorry, I have been at work too long today to do it).
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 03:11 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