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 :cool:

What error occurs? Could you post the exact error message?

this is the message:
"./005.aux: fork: Resource temporarily unavailable"

That loop is attempting to create an infinite number of background jobs. Do you expect it to succeed?

maybe? if it runs in foreground, there is no problem :frowning:
so, how could i do for running and exiting 005.aux in bg in each iteration?

sorry.. if i have basic questions

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?

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

while true
do
    ./005.aux &
    sleep 30
done

thank you very much ^^