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

📄 4.c

📁 实现进程间的创建、管理、软中断通信和管道通信
💻 C
字号:
#include<stdio.h>#include<stdlib.h>main(){         int pid1;//申请两个变量用来储存进程返回值         int pid2;         int x,fd[3];//fd数组用来标示接受和发送端口          char S[50];//用来存储字符          pipe(fd);//建立管道          pid1=fork();//建立子进程1          if(pid1==0){//子进程1          sprintf(S,"Child process one is sending message\n");              write(fd[1],S,37);//向管道写字符            }         else if(pid1>0){             pid2=fork();//建立子进程2              if(pid2==0){//子进程2                sleep(1);//停止1秒                sprintf(S,"Child process two is sending message\n");               write(fd[2],S,37);//向管道写字符              }             else{//主进程                 read(fd[0],S,37);//读第一个子进程写的字符                              for(x=0;x<37;x++)                   printf("%c",S[x]);                read(fd[0],S,37);//读第二个子进程写的字符                 for(x=0;x<37;x++)                                  printf("%c",S[x]);            }           }return 0;}

⌨️ 快捷键说明

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