2014-04-08 25 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));