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

📄 process_pipe.c

📁 进程管道通信
💻 C
字号:
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdio.h>
#include<errno.h>
#define INPUT 0
#define OUTPUT 1
int main(){
  int file1[3];
  //int file2[2];
  pid_t child1,child2;
  char buf1[256];
  char buf2[256];
  int returned_count;
  pipe(file1);
  // pipe(file2);
   if((child1=fork())==-1){
    printf("Fork Error:%s\n",strerror(errno));    exit(1);
  }
  if(child1==0){ 
    close(file1[INPUT]);
     write(file1[OUTPUT],"child1",6);
	      exit(0);
}  //close(file1[OUTPUT]);
  read(file1[INPUT],buf1,sizeof(buf1));  // printf("%s\n",buf2);  open(file1[OUTPUT]);  child2=fork();	if(child2==0){	  close(file1[INPUT]);       write(file1[OUTPUT],"child2",6);	      exit(0);}	close(file1[OUTPUT]);	read(file1[INPUT],buf2,sizeof(buf2));	printf("received from spawned process:\n%s\n%s\n",buf1,buf2);       return 1;       }

⌨️ 快捷键说明

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