Login or Register to Ask a Question and Join Our Community


finding Background Process Id


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding Background Process Id
# 1  
Old 10-24-2007
finding Background Process Id

Hi Gurus,
How can i find background process is completed or not. I have mentioned my scenario below.

Actually Pr1 Process is running in back ground, i just want to know whether this process completed or not. I can come to know the process id by typing pid=$! but i want to trigger that pr1 process in back ground and then after 10 min i want to trigger Pr2 Process. Actually Pr1 Process will take around 2 Hr time. i don't want to wait till 2Hrs, by writing wait $pid where $pid=$!.

script:
*****

x=`1 2 3 4 5`
for y in $x
do
if [ $a -eq 0 ]
then
./$Home/script_1.sh &
pid_1=$!
wait $pid_1
elif [ $b -eq 0 ]
then
./$Home/script_2.sh &
pid_2=$!
wait $pid_2
fi
sleep 15
done

here n this case for every 15 sec i want to run the scripts which has completed its process. in this case first it will run script_1.sh then it will wait for the process to complete then it triggers the script_2.sh but i don' t want to wait till script_1.sh completes. For every 15sec i want too run which ever is free i.e if for after 45 sec script_1.sh is completed its processing the it shuld run.


Please help me on the same.
# 2  
Old 10-24-2007
What you could do is have a temporary file which is created when you start to run a script, then you delete when the script finishes.

You then have a single loop with a sleep which looks at what temporary files exist and then decides what should be started.
# 3  
Old 10-24-2007
Hi,
can u send any sample code.
# 4  
Old 10-24-2007
something like...,

Code:
#!/bin/sh

rm dead.tmp

run_one()
{
    touch one.tmp
    ./one.sh
    rm one.tmp
    echo $$ >>dead.tmp
}

run_two()
{
    touch two.tmp
    ./two.sh
    rm two.tmp
    echo $$ >>dead.tmp
}

....

while true
{
       sleep 15

       if test -f dead.tmp
       then
          mv dead.tmp reap.tmp
          for d in `cat reap.tmp`
          do
             wait $d
          done
          rm reap.tmp
       fi

       for d in one two ....
       do
               if test ! -f $d.tmp
               then
                      run_$d &
                      break
               fi
       done
}

# 5  
Old 10-24-2007
Hi,
Thanks for responding...

Actually my requirement is as follows.

i had 5 Processes for every 30 min i want to run.for every 30 min i need to check which process is free.then i will kick off that process.

this scenario will work for the previous code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

3. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

4. Shell Programming and Scripting

Background Process.

How to create a backgrond processes ? (5 Replies)
Discussion started by: anupdas
5 Replies

5. Shell Programming and Scripting

background process

can anybody plz tell me how can i find the background processes running. (2 Replies)
Discussion started by: Raom
2 Replies

6. UNIX for Dummies Questions & Answers

background process

How, can I hide background process's output? (5 Replies)
Discussion started by: zylwyz
5 Replies

7. Shell Programming and Scripting

background process

Hi, In shell script when I use script1 >> filelog the echo statments of script1 gets printed in the filelog but when I try to run script in background i.e, script1 & >> filelog nothing gets printed in the filelog. Anybody knows whats going on here. thanks (3 Replies)
Discussion started by: k_oops9
3 Replies

8. Shell Programming and Scripting

process in background

Hi Guys, I am facing some weird problem with my shell script. The script shows up a menu and for every ontion internally calls a shell script which start/stop various servers. When I am using '&' while calling the internal shell script so that the server run in the background. For exiting... (1 Reply)
Discussion started by: agoyal
1 Replies

9. Programming

background process

I have made a shell that accept a command and parameters. It is working properly. I have tryed to implement background process in main(). But i dont know to implement them. Can anyone give me a lille example?? #include <stdlib.h> #include <stdio.h> #include <string.h> /* The following... (3 Replies)
Discussion started by: badshah
3 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question

Featured Tech Videos