How can I wait for PID to finish in another shell


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How can I wait for PID to finish in another shell
# 1  
Old 01-17-2005
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  
Old 01-17-2005
Just loop checking to see if the process is still running. If so, sleep for ten seconds and loop again. If not continue.
# 3  
Old 01-17-2005
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to wait for a grand child to finish?

Hello all, I have a very basic question. I have a requirement where in, I have a main process which forks a child process, which execs and runs a c executable corresponding to a daemon. In the c executable corresponding to a daemon, as everyone does, I fork another child process, and as part of... (7 Replies)
Discussion started by: sai2krishna
7 Replies

2. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

3. Shell Programming and Scripting

How to wait for tar to finish before sending the archive through ftp?

Hey all, I want to automate tarring a directory then using ftp to transfer the files over. I was able to put the commands together but what I'm noticing is that only the very first file is being tarred and then transferred. tar cvpf new.backup sourceAbove is the command I'm using which works... (4 Replies)
Discussion started by: Keepcase
4 Replies

4. Shell Programming and Scripting

How to WAIT for jobs in each group to finish?

I have the shell script to call a Perl routine and pass the Informatica WorkFlow name to it. Jobs in each group executes in background do not seem to wait at all. How do I make it to WAIT for the prior group to complete before execute the next group of jobs? Sample of the jobs flow: { ... (6 Replies)
Discussion started by: lv99
6 Replies

5. Shell Programming and Scripting

How to make parent shell finish last?

Hi all, I have a shell that kicks off several sub-shells and make them run parallelly, like: shell1.sh & shell2.sh & shell2.sh & ... However, since all sub-shells run parallely, the parent shell finished right after it's submitted, like: $ parent.sh & $ + Done parant.sh & $ ... (2 Replies)
Discussion started by: visio2000
2 Replies

6. Shell Programming and Scripting

shell script for getting pid of spawn processes from shell

Hi, I am new this forum. I request you peoples help in understanding and finding some solution to my problem. Here it goes: I need to perform this set of actions by writing a shell script. I need to read a config file for the bunch of processes to execute. I need to fecth the pid of... (4 Replies)
Discussion started by: sachin4sachi
4 Replies

7. UNIX for Dummies Questions & Answers

Wait Process in Shell Scripting.

Hello, I have a script that needs to wait till the previous process is done within the same script.But my script doesnt wait till that it is done.Can anyone suggest how I can stop my process till the previous task is done. I tried 'wait' but I dont have a static process id so is there... (2 Replies)
Discussion started by: sud
2 Replies

8. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

How to wait for the subprocess to finish in tcl

Hi All Here i have a piece of code, set filename "./GopiRun.sh" #I need to wait here until the GopiRun.sh is completed how do i achive this exit. (1 Reply)
Discussion started by: nathgopi214
1 Replies

10. Shell Programming and Scripting

wait in shell scripts

Hi I am creating 3 background processes in my shell script using &. I have obtained the 3 PIDs of the background processes using $!. I need to wait for these to complete and i need the exit status of each of these. If i use : wait $PID1 wait $PID2 wait $PID3 and get the exit status of... (1 Reply)
Discussion started by: Vinaya
1 Replies
Login or Register to Ask a Question