我有以下代碼: int main(void) {
char in[100];
printf("> ");
fgets(in, sizeof(in), stdin);
int pid;
char *f[100];
char *v;
int i = 1;
v = strtok(in, " ");
f[0] = v
現在我正在編寫一個必須執行子進程的C程序。我不是在同時進行多個子進程或任何事情,所以這相當簡單。我確實成功地執行了內置的shell程序(即cat和echo之類的東西),但是我也需要能夠判斷這些程序中的一個何時無法成功執行。我用下面的簡化的代碼嘗試這樣的: int returnStatus; // The return status of the child process.
pid_t pid
我試圖確定執行是否通過檢查waitpid函數的結果失敗()。但是,即使當我跑,我知道失敗並寫入這個問題到stderr命令,檢查以下從未登記。這段代碼可能有什麼錯誤? 感謝您的任何幫助。 pid_t pid; // the child process that the execution runs inside of.
int ret; // exit status of child proce