0

With the system functionlaunch a bash script. The function system waits for the bash script finished execution and I will return the exit status of the script.

The bash script in question, in its execution flow has a loop that executes n times the same script with different parameters.Obviously when the loop condition is no longer valid, the loop is terminated and the exit is invoked. In this way there are child processes of the executed script from perl function system that are zombies.

The system function does not wait for processes zombies but only the first script launched.

The my scenario is:

perl system function ---launch---> my bash script ---launch---> bash script
                                                                                    ---launch---> bash script
                                                                                    ---launch---> bash script
                                                                                    .............................
                                                                                    .............................
                                                                                    .............................
                                                                                    ---launch---> bash script

To wait until all processing is done, I have to change the bash script or function I can resolve directly with the function system perl?

4
  • Your Perl process can only wait for its own children to die; it cannot wait on its grandchildren. You need to distinguish between zombies (the living dead — processes that have died and not been waited for) and orphans (live processes whose parents have died). If the bash script leaves zombies around, the zombies will become children of the init process (a system process) that waits for children to die, and the zombies will vanish promptly. OTOH, if the child processes are still running, they're orhpaned and become children of the init process, but they won't stop until they complete. Commented Jan 21, 2014 at 15:56
  • @JonathanLeffler In fact, my problem is that the first script launches child processes, which create children then grandchildren of the first script. Should I wait until the end of execution of all processes. Commented Jan 22, 2014 at 16:42
  • That's exactly what I suggested in my answer. Commented Jan 22, 2014 at 17:24
  • I solved it by following all the flow of execution, executing any bash script in the background (&) and after adding the wait statement. This worked correctly. Commented Jan 28, 2014 at 9:17

1 Answer 1

0

Change the bash script you call from Perl so it does:

bash subprocess &
bash subprocess &
bash subprocess &
...
wait

then it will wait for all its own children to complete before it exits itself. For example

sleep 5 &
sleep 5 &
sleep 5 &
wait

will take 5 seconds to run.

Sign up to request clarification or add additional context in comments.

1 Comment

This solution dosn't work!!! The process excuted in background, but not expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.