为什么系统不返回main的值?

ask*_*ker 2 perl system

[root@ test]$ cat return10.c
#include <stdio.h>
int main(int argc, char *argv[]){
    return 10;
}
[root@ test]$ perl -e 'print system("/path_to_return10")'
2560
Run Code Online (Sandbox Code Playgroud)

我期待10但是得到2560,为什么?

Adr*_*son 6

system在perl中调用的文档中指定(http://perldoc.perl.org/functions/system.html):

返回值是等待调用返回的程序的退出状态.要获得实际退出值,请向右移动八(见下文).

确实: 2560 >> 8 = 10


Dal*_*aen 6

$?的perldoc perlvar.

你有10*256(返回值= 10)+ 0*128(没有核心转储)+ 0(进程没有被信号杀死).