thanks monk,
for example, if i write a C program as below:
main()
{
exit(100);
}
then, i invoke it from perl, and print the exit code, it's 25600. it convert to binary is: 1100100 00000000. so the high 8 bits is: 1100100(100), and the low 8 bits is: 00000000. if this C programm ran abnormally, the low 8 bits may contain info of interest, so use $? & 127 OR $? & 128. am'i right? | [reply] |
You want 8 bits, not 7. IMHO, if you are doing bit operations, you should use hex (or octal if you are old-school) representations, so that it is clear. In this case, you should & with 0xff
| [reply] |
In this case, you should & with 0xff
Actually, I think it's sufficient to use $? & 0x7f (or $? & 127 in decimal) to test for abnormal termination. That's what the code snippet in system suggests. Also, the system header files responsible for the exit status handling (e.g. /usr/include/bits/waitstatus.h in my case) usually define those macros (among others):
#define __WTERMSIG(status) ((status) & 0x7f)
/* Nonzero if STATUS indicates normal termination. */
#define __WIFEXITED(status) (__WTERMSIG(status) == 0)
(from that I would conclude that the core-dumped bit ($? & 128) doesn't occur in isolation (i.e. without WTERMSIG being non-zero) ) | [reply] [d/l] [select] |