Hi list, I am currently having an issue with background processes. I already searched the web and found a way how to principally send a process into background, wait for the execution to finish and then go on with the main program:
my $pid = fork; if ( $pid ) { wait; print "done.\n"; } else { print "starting.\n"; system "compress *.dbf &"; exit; } The "done." is being issued at the correct point of time, namely when really all files have been compressed. Unfortunately, this only compresses one file after the other and therefore lacks performance. So I tried to send multiple processes into background and have them to be executed simultaneously. I tried the following: my $pid = fork; if ( $pid ) { wait; print "done.\n"; } else { print "starting.\n"; foreach ( glob "*.dbf" ) { system "compress $_ &"; exit; } This behaves as expected, from the "simultaneous" and "background" point of view - but my big problem is now that the message "done." is being issued as soon as all the compression processes are ISSUED instead of when they are FINISHED. Could anybody please point me into the right direction how to best solve that issue? Maybe I should fork all the single compression processes to get a pid for each, put them into an array and check with a loop whether they still exist (process running)? Would there be another / easier / more efficient way? Thanks in advance, Nora