Do you know where your variables are? | |
PerlMonks |
Re: Problem with exit status of bash scriptby Athanasius (Archbishop) |
on Dec 04, 2014 at 04:41 UTC ( [id://1109195]=note: print w/replies, xml ) | Need Help?? |
Hello dizzyd719, and welcome to the Monastery! If your code:
worked as you expect, what advantage would there be in backgrounding the ping process? Whether running in the foreground or the background, it would still have to complete before the system call returned. But with ping backgrounded you report a significant speedup. I suspect what is happening is this: the call to system("ping ... &") spawns a shell subprocess (1) which in turn spawns the call to ping as a background process (2). Process (1) then immediately returns to the system call a status code indicating whether process (2) was spawned successfully. So of course you aren’t getting the correct exit statuses, since the return values from (2) never make it back to your Perl script. The speedup you are seeing suggests that you will indeed benefit from running the ping commands in parallel (asynchronously). So you need another way to do this and get their exit statuses. Have a look at fork or a module such as Parallel::ForkManager. (And see perlfaq8#How-do-I-start-a-process-in-the-background%3f.) Hope that helps,
In Section
Seekers of Perl Wisdom
|
|