Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第5章 8.c #11

Open
DonkiChen opened this issue Sep 12, 2024 · 0 comments
Open

第5章 8.c #11

DonkiChen opened this issue Sep 12, 2024 · 0 comments

Comments

@DonkiChen
Copy link

题目要求是 "使用pipe()系统调用,将一个子进程的标准输出连接到另一个子进程的标准输入",但是代码中直接向管道写了

  if (pid == 0) {
    int ppid = fork();
    if (ppid == 0) {
      char *msg = "Hello!\n";
//      关闭多余管道端
      close(fd[0]);
      write(fd[1], msg, sizeof(char) * strlen(msg));
    } else if (ppid > 0) {
      wait(NULL);
      char asw[10];
      close(fd[1]);
      int res = read(fd[0], asw, sizeof(char) * 10);
      printf("size:%d, %s", res, asw);
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant