Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: return value from system call, exit status, shift right 8, bitwise and, $?

by Anonymous Monk
on Feb 11, 2010 at 15:03 UTC ( [id://822664]=note: print w/replies, xml ) Need Help??


in reply to Re: return value from system call, exit status, shift right 8, bitwise and, $?
in thread return value from system call, exit status, shift right 8, bitwise and, $?

Ok. I think I see now. If the system() call returns "-1", this is the same as a binary number of all 1's (since the system presumably uses the two's-complement representation), and it looks like it is:

printf '%b', -1; print "\n"; # Output is: # 11111111111111111111111111111111

So, if we get -1 back, then I can just stop checking bits right there.

If the system() call does not return -1, but returns anything at all in those first 7 bits, then -- again -- I can stop checking anything else, because if those first 7 bits contain anything, that indicates that the program that was called received a signal and that's why it ended.

Finally, if the system() call does not return -1, and those first 7 bits are all zeros, then only at that point do those next 8 bits contain anything of interest (the exit status of the program called).

And to wrap this all up nicely, if the system() call returns 0, then that means all bits are off, thus:

  1. the value is not -1, so the program it called at least launched,
  2. the lower 8 bits are all zeros, so there was no signal caught (nor was a core dump saved),
  3. the higher 8 bits are all zeros, so exit status was zero too.

and therefore the program that system() called evidently ran successfully.

Thank you!

  • Comment on Re^2: return value from system call, exit status, shift right 8, bitwise and, $?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-26 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found