How can I make Perl wait for child processes started in the background with system()?

前端 未结 3 2224
醉梦人生
醉梦人生 2021-02-14 10:41

I have some Perl code that executes a shell script for multiple parameters, to simplify, I\'ll just assume that I have code that looks like this:

for $p (@a){
           


        
3条回答
  •  自闭症患者
    2021-02-14 11:15

    Converting to fork() might be difficult, but it is the correct tool. system() is a blocking call; you're getting the non-blocking behavior by executing a shell and telling it to run your scripts in the background. That means that Perl has no idea what the PIDs of the children might be, which means your script does not know what to wait for.

    You could try to communicate the PIDs up to the Perl script, but that quickly gets out of hand. Use fork().

提交回复
热议问题