background problem in while loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting background problem in while loop
# 1  
Old 07-06-2005
background problem in while loop

file 005:
trap 'echo "\nInterrupcion recibida.Saliendo\n\n" ; exit 0 ' 2 9 15

while true
do
./005.aux &
done



005.aux:

trap 'exit 0' 2 9 15
sleep 30
exit 0

The error ocurrs if i try to execute 005.aux in background. How could i resolve it? Thanks Smilie
# 2  
Old 07-06-2005
What error occurs? Could you post the exact error message?
# 3  
Old 07-06-2005
this is the message:
"./005.aux: fork: Resource temporarily unavailable"
# 4  
Old 07-06-2005
That loop is attempting to create an infinite number of background jobs. Do you expect it to succeed?
# 5  
Old 07-06-2005
maybe? if it runs in foreground, there is no problem Smilie
so, how could i do for running and exiting 005.aux in bg in each iteration?


sorry.. if i have basic questions
# 6  
Old 07-06-2005
You can't create a new background process which each iteration. You will run out of resources. When you run it in the foreground, you wait for it to finish then create a new process. You can use the wait command to wait for the background process, but what is the point of that?
# 7  
Old 07-06-2005
Here's why it fails in bg:

The while loop can make 300000 in 30 seconds. That's 300000 separate processes all running AT THE SAME TIME. Your system cannot have that many processes going at the same time.

When you run it in fg, it creates one process at a time. One process vs. 300000.

To make it work try something like this
Code:
while true
do
    ./005.aux &
    sleep 30
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with loop within loop

Hi, I work on Ab-initio ETL tool which is based on Unix. I made a small script which has two loop's one with in another. All the functionality is working for the first line of outer loop but when it comes to other lines of outer loop it is throwing error as command not found. Below is the... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

2. Shell Programming and Scripting

While loop hangs in function running in background

Hello Everyone, I am writing a shell script to fetch log files from remote servers within a time range. It copies log files to local server, grep for date and then compares the time stamp of each log entry with the once specified. Below is the code. # Get log and Parsing function ... (1 Reply)
Discussion started by: kanagalamurali
1 Replies

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

4. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

5. Shell Programming and Scripting

Background tasks in a loop (bash)

I am trying to use a loop to start tasks 0-3, running 0,1,2 in the background with &. FOLDSET=( 0 1 2 3 ) for FOLDSET in ${FOLDSET} do if ; then BACKGRD="&" else BACKGRD="" fi # start task $FOLDSET task1 -nogui -ni -p $PROJ \ epochs=$EPOS ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

6. Shell Programming and Scripting

Need to run the script in background, but having a problem

hi, we have a script which runs for the whole day and whenever the job fails, will send an alert to the mailbox. My problem here is that i need to give the jobname dynamically which is not possible if we run the script in background. Pls help me with this. Thanks Ajay (6 Replies)
Discussion started by: ajayakunuri
6 Replies

7. Shell Programming and Scripting

Problem with Background Jobs

We had a generic process where the jobs are scheduled to run sequentially and in background. We are noticing the problems with the background jobs. Error Message: /bin/ksh: /home/suren/bin/GenericReportScript.sh: cannot execute The same script is existing in bin and it had enough... (2 Replies)
Discussion started by: sureng
2 Replies

8. Shell Programming and Scripting

kill PID running in background in for loop

Guys, can you help me in killing the process which is running in back ground under for loop I am not able to find the PID using ps -afx|grep <word in command I entered> (1 Reply)
Discussion started by: mohan_xunil
1 Replies

9. Shell Programming and Scripting

Loop Problem

Hi , I have a file like this parentid process id 45 3456 1 7898 45 7890 1 6789 45 7597 now i need to... (5 Replies)
Discussion started by: namishtiwari
5 Replies

10. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies
Login or Register to Ask a Question