Linux,C++,负退出代码,澄清? [英] Linux,c++, negative exit codes, clarifiction?
问题描述
在 Linux 中,c++ 可以返回退出代码吗?即此代码是否有效:
int main(){返回-1;}
我问这个代码是否是从 bash/zsh 编译和执行的原因,返回值将是 255,我认为这是因为它使用 8 位返回码,这意味着返回码是只允许在正数之间.
这对吗?
相关的系统调用是_exit()
,POSIX 本身指定只有 _exit()
的状态的低 8 位是正常可用的:p><块引用>
_exit(状态)
status 的值可以是 0
、EXIT_SUCCESS
、EXIT_FAILURE
或任何其他值,尽管只有最低有效 8 位(即 status & 0377
) 应可从 wait()
和 waitpid()
获得;
虽然它继续说完整的值应从 waitid()
获得",但在 Linux 上,我似乎仍然只得到低八位.
In Linux, c++ can we return exit codes? i.e is this code valid:
int main()
{
return -1;
}
The reason I am asking if this code is compiled and executed from bash/zsh, the return value would be 255, I thin this due to the fact that its using an 8 bit return code, and that implies that return codes are only allowed to be between positive.
Is this correct?
The relevant system call is _exit()
, and POSIX itself specifies that only the bottom 8 bits of the status given to _exit()
are normally usable:
_exit(status)
The value of status may be0
,EXIT_SUCCESS
,EXIT_FAILURE
, or any other value, though only the least significant 8 bits (that is,status & 0377
) shall be available fromwait()
andwaitpid()
;
Though it goes on to say that "the full value shall be available from waitid()
", but on Linux, I seem to still get just the low eight bits.
这篇关于Linux,C++,负退出代码,澄清?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!