Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Problem with exit status of bash script

by Athanasius (Archbishop)
on Dec 04, 2014 at 04:41 UTC ( [id://1109195]=note: print w/replies, xml ) Need Help??


in reply to Problem with exit status of bash script

Hello dizzyd719, and welcome to the Monastery!

If your code:

system("ping ... &"); $result = $?;

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,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Problem with exit status of bash script
by dizzyd719 (Novice) on Dec 04, 2014 at 06:09 UTC

    Thanks, yeah after spitting out the errors codes (always 0) I realized that I wasn't getting the correct codes. I started looking into the "fork" option and just figuring out how to communicate between processes.

    do you have any good docs for me to read about IPC in perl? my research so far is leading me into "ALERTING A PROCESS VIA A SIGNAL"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1109195]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found