Wait for all processes started by a command or script executed with the function system perl

StackOverflow https://stackoverflow.com/questions/21257978

سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top