我有一個簡單的c程序,執行'ps'並將其管理爲'grep',基本上'ps | grep x'。ps命令linux vs unix在c程序中的不同行爲
代碼去更多或東西少這樣的:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(){
int pipefd[2];
int pid;
pipe(pipefd);
pid=fork();
if (pid == 0){
close(pipefd[1]);
dup2(pipefd[0], 0);
close(pipefd[0]);
execlp("grep", "grep", "b", (char *) 0);
}
else{
close(pipefd[0]);
dup2(pipefd[1], 1);
close(pipefd[1]);
execlp("ps", "ps", (char *) 0);
}
exit(0);
}
,我有是,當我在UNIX(Solaris)上運行,這是完美的作品,但是當我上運行此(Debian的)問題它正確執行,但給我一個錯誤消息。
錯誤消息:
Signal 17 (CHLD) caught by ps (procps-ng version 3.3.3).
ps:display.c:59: please report this bug
我已經嘗試運行像「LS」和「grep」可以與任何操作系統沒有問題不同的命令相同的程序。是什麼讓'ps'不同?
編輯:
添加包含庫的代碼。
嘗試閱讀關於'SIGCHLD'。 – icktoofay
謝謝,這實際上很有幫助。我正在搜索'信號17',但沒有得到任何有用的信息。現在已經很晚了,明天我會花一些時間研究它。 – Lex