Liunx 进程和pipe()管道问题(求大神回答)

伊斯坦堡 发布于 2015/05/01 19:53
阅读 143
收藏 0
GCC


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>

int main()
{
    int pid1,pid2;
    int pfd[2];

    pipe(pfd);

    pid1=fork();
    if(pid==0)
    {
       char *argv[]={
          "echo",
          "good morning",
          NULL
       };

       close(pfd[0]);
       close(1);
       dup(pfd[1]);
       close(pfd[1]);
       execvp("echo",argv);
       exit(1);
    }
    pid2=fork();
    if(pid2==0)
    {
       char *argv[]={
          "sed",
          "s/good/hi/g",
          NULL
       };
       close(pfd[1]);
       close(1);
       dup(pfd[0]);
       close(pfd[0]);
       execvp("sed",argv);
       exit(1);
    }
    close(pfd[0]);
    close(pfd[1]);
    wait(NULL);
    wait(NULL);
    return 0;

}

错误信息:
 xie.c:14: error: ‘pid’ undeclared (first use in this function)
xie.c:14: error: (Each undeclared identifier is reported only once
xie.c:14: error: for each function it appears in.)

加载中
0
木子叶
木子叶
不会看错误提示吗,变量pid没声明,C语言还没学就不要学管道了
返回顶部
顶部