> > When displaying the value of ret, I get 512. The value being
> > returned to programA seems to be bit-shifted left by 1 byte.
> That's right.
> > Can anyone explain this to me.
> Your manual page can:
I agree with you in spirit, but *my* system(3) man page doesn't
explain it at all. To look it up, you have to know to look under
`wait(2)'. A beginner isn't going to make this connection. In fact,
on my system, even `wait(2)' doesn't tell you what's going on; all it
tells you to do is to use the W...() macros to get the status. This
is pretty unhelpful.
Gary: Yes, it is left-shifted by 8 bits, as you've noticed. This is
because the low 8 bits contain information about whether the process
was stopped by a signal, and what signal it was, and whether it left a
core file behind. What you should so is first check if the result is
127, because `system' uses that to indicate that it couldn't run the
command at all; then if it's not 127, rightshift it 8 places to get
the real return status.
The night is pleasing to us because, like memory, it erases idle details.