in reply to Re: Process exit status
in thread Process exit status

Yes, you're right. It's mentioned in the docs of system. But it still does not help me to understand why the process exit code is shifted and why not only one byte is used although it would fit into one byte. I don't understand the why.

I wanted to have background information of you. Of course I can do the reading of the docs myself. Perhaps the formulation of my question (using the words unexpected and strange) was leading to the assumption that I did not read the docs of system before posting here a question.

Replies are listed 'Best First'.
Re^3: Process exit status
by JavaFan (Canon) on Jul 22, 2011 at 14:03 UTC
    Perhaps the formulation of my question (using the words unexpected and strange) was leading to the assumption that I did not read the docs of system before posting here a question.
    It certainly did. Specially since the documentation says that the lower 8 bits don't have to be 0 - they are non-zero if the program exits because of receiving a signal, and/or dumped core. Given this, dividing the exit code by 256 is wrong, as Perl doesn't do integer arithmetic by default. The documentation says one should shift 8 bits - which you don't do. So, not only does the phrasing of your question suggests you haven't read the documentation, your code does the same.

      To be honest. I did not understand the explanation in system. So I tried myself to understand it. This lead me to a sample program in which I then finally used the division by 256, although you are right that it is clearly stated in the docs that a 8bits shift to the right has to be done to get the exit code.

      Now I understand the explanation well. The example at the end with $? also shows that the signal id is the other part of the exit status.

      My problem was that the explanation did not state explicitly that the return value of "system" is 16 bits, and that the lower 7 bits are the signal id which caused the process to die. With this bit representation in my mind I would not have needed to ask you.

      Thank you for your help. And next time I will ask clearer what I exactly want to know and what part of the docs I don't understand.

Re^3: Process exit status
by Anonymous Monk on Jul 22, 2011 at 13:40 UTC