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

📄 pipe.c

📁 操作系统Interprocess Communication(IPC)实验源码。 在Unix的内核环境中
💻 C
字号:
#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <errno.h>#define FD_READ  0#define FD_WRITE 1#define BUF_LEN 100int main(){  pid_t pid;  int fildes[2];  char buf[BUF_LEN];  if (pipe(fildes)<0) {    perror("pipe");    exit(1);  }  if ((pid=fork())<0) {    perror("fork");    exit(1);  }  /* create a pipe from father to child */  if (pid>0) {     /*in child process*/    printf("In child process\n");    close(fildes[FD_WRITE]);  /* close write fd */    if (read(fildes[FD_READ],buf,sizeof(buf))>0) {      printf("Read String:%s\n",buf);    }  } else {    printf("In father process\n");    close(fildes[FD_READ]);   /* close read fd */    if (write(fildes[FD_WRITE],"Hello World",sizeof("Hello World"))<0) {      perror("write");    }  }  return 0;}    

⌨️ 快捷键说明

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