下面我写了一个hello world程序,一起看看吧:
// filename: main.c #include <stdio.h> int main(void) { printf("hello wolrd!\n"); return(-); }编译执行:gcc main.c && ./a.out
现在我们看看在当前shell中返回上一个执行过程的返回值是多少,是 “-1” 吗?
inuyasha@inuyasha-Aspire-4741:~/桌面$ gcc main.c && ./a.out
hello world!
inuyasha@inuyasha-Aspire-4741:~/桌面$ echo $?
255
啊,结果为什么 "255"呢?调用一个程序, 程序退出-1, 得到结果不是“-1”吗?
以下引用自:http://mand Possible problem with$PATHor a typo 128 Invalid argument toexit exit 3.14159 exittakes only integer args in the range0 – 255(see first footnote) 128+n Fatal error signal”n” kill -9$PPIDof script $?returns137(128 + 9) 130 Script terminated by Control-C Control-C is fatal error signal2, (130 = 128 + 2, see above) 255* Exit status out of range exit-1 exittakes only integer args in the range0 – 255