Help puting background process ID's into an array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help puting background process ID's into an array
# 1  
Old 07-15-2009
Help puting background process ID's into an array

I am trying to write a script that runs another script consecutively and records the PID of the called script each time it runs in an array.
I put in an echo statement to check the PID, when the script runs no PID is output, and the array seems to be empty. I assume it is problem with my code, but kind of stuck as to where.

Code:
i=0

while [ $i -lt 5 ]
   do
        ./script
        array[$i]=$!
       echo $! #there to test that the PID exists
       let i=i+1
   done

# 2  
Old 07-16-2009
any takers?
# 3  
Old 07-16-2009
The syntax looks fine. But if you don't run ./script in the background it will have finished before you try to capture the pid.

ie.
Code:
/root # sleep 1
/root # echo $!
 
/root # sleep 10 &
[1]     2971
/root # echo $!
2971

# 4  
Old 07-20-2009
I was missing the "&", that made it work. Thanks!
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

Need help on Assigning a Array variable from Background Functions

I have a question on how can I assign a output of a function to a variable which is executed in background. Here is my example $ cat sample_program.sh #!/bin/ksh exec_func () { sleep 1 v=`expr $1 + 100` print $v } export OUT_ARR date for i in 1 2 do OUT_ARR=`exec_func $i` &... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

3. 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

4. Shell Programming and Scripting

Using eval to populate an array in the background

Hi. I am trying to populate an array using eval in the background within a function. So this function will create a list of 3 character directories from SVN and store in an array. I want to call this function when the script starts in the background unknown to the user. The problem is that... (2 Replies)
Discussion started by: jmiaebrown
2 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Background Process

I need to submit a script that will continue to run after logging out and after a reboot or shutdown. I entered the following: nohup script & The script continues to run in the background after logging off the system but is killed after a reboot or shutdown. Any help would be greatly... (1 Reply)
Discussion started by: powwm
1 Replies

7. Shell Programming and Scripting

Background Process.

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

8. 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

9. UNIX for Dummies Questions & Answers

background process

How, can I hide background process's output? (5 Replies)
Discussion started by: zylwyz
5 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