Linux中有任何标准的退出状态代码吗?如果进程的退出状态为0,则认为它在Linux中已正确完成。我已经看到,分段错误通常会导致退出状态为11,但我不知道这是否只是我工作的惯例(那些失败的应用程序都是内部的)还是一个标准。Linux中的进程是否有标准的退出代码?
3 回答
侃侃尔雅
TA贡献1801条经验 获得超16个赞
wait(2)
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include <signal.h>int main() { int status; pid_t child = fork(); if (child <= 0) exit(42); waitpid(child, &status, 0); if (WIFEXITED(status)) printf("first child exited with %u\n", WEXITSTATUS(status)); /* prints: "first child exited with 42" */ child = fork(); if (child <= 0) kill(getpid(), SIGSEGV); waitpid(child, &status, 0); if (WIFSIGNALED(status)) printf("second child died with %u\n", WTERMSIG(status)); /* prints: "second child died with 11" */}
$ sh -c 'exit 42'; echo $? 42 $ sh -c 'kill -SEGV $$'; echo $? Segmentation fault 139 $ expr 139 - 128 11
SIGSEGV
exit
SIGKILL
SIGSTOP
.)
- 3 回答
- 0 关注
- 605 浏览
添加回答
举报
0/150
提交
取消