background process return code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting background process return code
# 1  
Old 06-09-2006
background process return code

Hi
I have the following piece of code that is calling another child process archive.ksh in the background

while read file;
do
file_name=`ls $file`;
ksh archive.ksh $file_name &;
done < $indirect_file

The problem is, indirect_file may contain anwhere from 2 to 20 different filenames and archive.ksh takes only one file name at a time (that is a limitation). So based on the number of files in indirect_file, i shall run those many background processes for archive.ksh.

I need to check for the completion of all archive.ksh jobs that i fired in the background and only if all the bg jobs are successful, i need to make this process pass otherwise I abort it.

I found that there is a wait command that will wait for bg jobs to finish..Can I use it? if yes, how do i overcome following prob :

1. How do I specify the job id or pid to wait command when I dont know it beforehand?

2. I have heard that there is a restriction on the number of jobs you can fire? What is the number?

Any ideas??

Thanks
# 2  
Old 06-09-2006
start with something like this:
Code:
#!/bin/ksh

>logfile

echo "start time `date`" > logfile

while read file
do
    file_name=`ls $file`;
    (ksh archive.ksh $file_name; echo "$file_name status=$?">> logfile)&
done < $indirect_file
wait

echo "end time `date`" >> logfile
cat logfile

I have not tested this...
# 3  
Old 06-09-2006
Just one more question

Jim

Thanks for your reply

Per your code, does "wait" wait for all the bg jobs? I had heard there was some kind of upper limit.

Thanks
# 4  
Old 06-09-2006
25 is the upper limit

Jim

Once again, thanks for your script. I tested it out and found out that there is a upper limit of 25. Contrary to what I thought, it looks like 25 is not the limit of "wait" but apparantly it is the limit on number of background job I can submit.

If I want to run the archive script for even 26 times, it gives me following error:

bg.ksh[6]: cannot fork - try again

I guess this is some sort of limit set by sysadmin??

Anyways, for the time being, i guess that would serve my purpose.

Thanks again
# 5  
Old 06-10-2006
The limit is usually a system parameter.
if your limit is 25 try this:
Code:
#!/bin/ksh

>logfile

echo "start time `date`" > logfile
let counter=0
while read file
do
    file_name=`ls $file`;
    (ksh archive.ksh $file_name; echo "$file_name status=$?">> logfile)&
    let counter=$counter+1
    if [ `echo "$counter%25" | bc` -eq 0 ] ; then
          wait
    fi
done < $indirect_file
wait

echo "end time `date`" >> logfile
cat logfile

# 6  
Old 06-10-2006
Thats is great and good idea .. hope it will work...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to return from background process and check if it is running or not?

Hi Team, i am executing 3 scripts in background from 1 script and i want to send a message once the script gets completed.these scripts usually takes 1 hr to complete. My sample script is below, Vi abc.sh sh /opt/data/Split_1.sh & sh /opt/data/Split_2.sh & sh /opt/data/Split_3.sh & ... (3 Replies)
Discussion started by: raju2016
3 Replies

2. Shell Programming and Scripting

Pass return value of a function in background process

Hi, I have created a function f1 defined in script A.sh .I have called this function in background . But I want to use its return value for another function f2 in script A.sh. I tried declaring it as a global variable, yet it always returns the status as 0. Is there any way with which I can get... (7 Replies)
Discussion started by: ashima jain
7 Replies

3. Shell Programming and Scripting

Capturing the return code from background process

Hi All, I was out not working on unix from quite sometime and came back recently. I would really appreciate a help on one of the issue I am facing.... I am trying to kick off the CodeNameProcess.sh in PARALLEL for all the available codes. The script runs fine in parallel. Let say there are... (1 Reply)
Discussion started by: rkumar28
1 Replies

4. Shell Programming and Scripting

Catch exit code of specific background process

Hi all, i hava a specific backgroud process. I have de PID of this process. At some time, the process finish his job, is there any way to catch the exit code? I use "echo $?" normally for commands. Thanks! (2 Replies)
Discussion started by: Xedrox
2 Replies

5. Shell Programming and Scripting

Background process, return code and pid.

Hey all, Okay, this one is tricky and I'm not sure there is a niec way to do it, or indeed anyway to do it. The main issue revolves around timing out a hung ssh. I am doing this by creating a wrapper script for the ssh with the following requirements. My requirements are: Defineable... (5 Replies)
Discussion started by: RECrerar
5 Replies

6. Shell Programming and Scripting

return code of multiple java process

Hi, I have a unix shell script which is launching multiple java processes by calling a java class in a loop, but each time with a different set of parameters. Now I have to use the return code from each process in the script later. but how do i obtain the return code from each process... (1 Reply)
Discussion started by: rama354
1 Replies

7. Shell Programming and Scripting

Return code of background process

Hi, I have a process that I run in the background that looks like this ${BASEDIR}/ksh/sqler.ksh ${compnames003} & and I would like to get the return code of the sqler.ksh script. so my code is like this ${BASEDIR}/ksh/sqler.ksh ${compnames003} & retcode=$? (3 Replies)
Discussion started by: c19h28O2
3 Replies

8. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

9. Programming

return code of a process

two programs A and B writting in c++ I am using A to B and I want to know the return code of B. in B ------------------------ int main() { return 11; } ------------------------ in A ------------------------ int main() { system(A); } ------------------------ Is it the right way... (1 Reply)
Discussion started by: filedeliver
1 Replies

10. UNIX for Advanced & Expert Users

return code of a process

two programs A and B writting in c++ I am using A to B and I want to know the return code of B. in B ------------------------ int main() { return 11; } ------------------------ in A ------------------------ int main() { system(A); } ------------------------ Is it the right way... (1 Reply)
Discussion started by: filedeliver
1 Replies
Login or Register to Ask a Question