[英]WC isn't executing anything
誰能告訴我這是怎么了? 我仍然是新手。 計算機執行第一個和第二個,但是執行wc的第三個不起作用。 急需幫助。 終端返回已完成但沒有wc的多個子進程。
pid_t son;
int i;
for (i=0; i<=3; i++){
switch (i){
case 0:
son = fork();
if (son<0){
fprintf(stderr, "Fork failed!");
//exit(-1);
}else if (son == 0){
execlp("/bin/cat", "cat", "wctrial.txt", NULL);
exit(0);
}else{
wait(NULL);
printf("Child process completed!");
}
case 1:
son = fork();
if (son<0){
fprintf(stderr, "Fork failed!");
//exit(-1);
}else if (son == 0){
execlp("/bin/mkdir", "mkdir", "mydirectory", NULL);
exit(0);
}else{
wait(NULL);
printf("Child process completed!");
}
case 2:
son = fork();
if (son<0){
fprintf(stderr, "Fork failed!");
//exit(-1);
}else if (son == 0){
printf("Work!");
execlp("usr/bin/wc","wc","-w","wctrial.txt", NULL);
exit(0);
}else{
wait(NULL);
printf("Work!");
printf("Child process completed!");
exit(0);
}
}
}
}
由於功能請求將評論標記為答案的請求仍然被拒絕,因此我將上述解決方案復制到此處。
您忘記了路徑中的前導斜線。 –約阿希姆·皮爾博格
“ usr / bin / wc”應為“ / usr / bin / wc” – Basile Starynkevitch
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.