2014-04-08 24 views
1

我想调用一个程序并获得它的返回值。我用fork()execv()来调用子进程,现在正在等待状态,但我收到56作为退出状态,我不明白为什么。我已经单独检查了子进程,它工作得很好。退出状态56时调用子进程

56是什么意思,我该如何解决?


这是一部分相关代码:

pid_t pid = fork(); 

if (pid < 0)     
    // handle error 

if (pid == 0) 
    execv(filename, argv); // calls child process 

waitpid(pid, &status, 0); 

if (WIFEXITED(status))  
    // handle success 
else if(WIFSIGNALED(status)) 
    printf("%d\n", (int) WTERMSIG(status)); // here I get 56 now, when I print the error using stderror I get this: "Invalid request code" 
+3

请显示一些相关的代码。 –

+2

这非常含糊,程序输出不同的退出代码。尝试在您的子进程中执行您正在执行的程序,看看它是否有退出代码列表。 – photoionized

+0

你有没有考虑过使用errno? – squiguy

回答

2

不打印退出状态,但终止的进程的信号的数量。当子进程正常退出(WIFEXITED)时,您不会打印任何内容。 应该是这样的:

if (WIFEXITED(status))  
    printf("%d\n", (int)WEXITSTATUS(status));