⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pipe.c

📁 1、 了解系统调用pipe()的功能和实际原理 2、 编写一段程序
💻 C
字号:
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{int fd[2];
 pid_t x;
 char S[100];
 pipe(fd);
 x = fork();
 if (x == 0)
 { printf("Child Process<%d> Send Hello to Father Process!\n", getpid());
   sleep(1);
   sprintf(S, "Hello from Child Process!");
   close(fd[0]);
   write(fd[1], S, 50);
   close(fd[1]);
   sleep(1);
 }
  else 
  {//wait(0);
   close(fd[1]);
   read(fd[0], S, 50);
   close(fd[0]);
   printf("Father Process<%d> receive the message : ** %s **\n", getpid(), S);
  }
 return 0;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -