📄 guandao.txt
字号:
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
int pid1,pid2;
int main()
{
int fd[2];
char OutPipe[100], InPipe[100];
pipe(fd);
while((pid1 = fork()) == -1);
if( pid1 == 0)
{
lockf( fd[1], 1, 0 );
sprintf(OutPipe, "\n Child process 1 is sending message!\n");
write( fd[1], OutPipe, 50);
sleep(5);
lockf(fd[1], 0 , 0);
exit(0);
}
else
{
while((pid2 = fork()) == -1);
if( pid2 == 0)
{
lockf( fd[1], 1, 0 );
sprintf(OutPipe, "\n Child process 2 is sending message!\n");
write( fd[1], OutPipe, 50);
sleep(3);
lockf(fd[1], 0 , 0);
exit(0);
}
else
{
wait(0);
read(fd[0], InPipe, 50);
printf("%s\n", InPipe);
wait(0);
read(fd[0], InPipe, 50);
printf("%s\n", InPipe);
exit(0);
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -