简体   繁体   English

WC没有执行任何操作

[英]WC isn't executing anything

Can anyone tell me what's wrong with this? 谁能告诉我这是怎么了? I'm still a newbie with forking. 我仍然是新手。 The computer executes the 1st and 2nd but the 3rd which is wc doesn't work. 计算机执行第一个和第二个,但是执行wc的第三个不起作用。 Need help badly. 急需帮助。 The terminal returns multiple child process completed but no 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);
                }
        }
}

} }

Since feature requests to mark a comment as an answer remain declined, I copy the above solution here. 由于功能请求将评论标记为答案的请求仍然被拒绝,因此我将上述解决方案复制到此处。

You forgot the leading slash in the path. 您忘记了路径中的前导斜线。 – Joachim Pileborg –约阿希姆·皮尔博格

"usr/bin/wc" should be "/usr/bin/wc" – Basile Starynkevitch “ usr / bin / wc”应为“ / usr / bin / wc” – Basile Starynkevitch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM