2
glibc documentation on process completion status指出宏WEXITSTATUS返回完成狀態的低位8字節。glibc文檔和字節順序
宏:int WEXITSTATUS(INT狀態)
如果WIFEXITED是身份true,則此宏返回低位從子進程的退出狀態值的8位。
然而,/usr/include/sys/wait.h
說:
# define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status))
而且,/usr/include/bits/waitstatus.h
提到:
/* If WIFEXITED(STATUS), the low-order 8 bits of the status. */
#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)
,除非我的字節序的概念都搞砸了,這是怎麼了低位 8位?或者是libc假設數據是以小端的方式保存的?
該文檔顯示「低8位」,因爲儘管子進程可以有任何「int」返回值,但在Posix環境中,只有該狀態的最低有效8位返回給父進程。 http://pubs.opengroup.org/onlinepubs/009695399/functions/_exit.html – JeremyP 2011-05-10 11:11:18