Skip to content

Commit

Permalink
11进程间通信
Browse files Browse the repository at this point in the history
  • Loading branch information
NaZixia committed Feb 27, 2024
1 parent 232c537 commit f4cb176
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Binary file modified 11进程间通信/1管道/pipe2
Binary file not shown.
2 changes: 1 addition & 1 deletion 11进程间通信/1管道/pipe2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ int main(){
}
else{
read(fds[0],buf,BUF_SIZE);
sleep(3);
write(fds[1],str2,sizeof(str2));
cout<<"fat:"<<buf<<endl;
sleep(3);
}


Expand Down
Binary file added 11进程间通信/1管道/pipe3
Binary file not shown.
34 changes: 34 additions & 0 deletions 11进程间通信/1管道/pipe3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <unistd.h>
using namespace std;

#define BUF_SIZE 30


int main(){

int fds1[2],fds2[2];
char str[]="who are you";
char str2[]="thank you for your message";
pid_t pid;
char buf[BUF_SIZE];

pipe(fds1);
pipe(fds2);

pid=fork();
if(pid==0){
write(fds2[1],str,sizeof(str));
read(fds1[0],buf,BUF_SIZE);
cout<<"child:"<<buf<<endl;
}
else{
read(fds2[0],buf,BUF_SIZE);
write(fds1[1],str2,sizeof(str2));
cout<<"fat:"<<buf<<endl;
}


return 0;

}

0 comments on commit f4cb176

Please sign in to comment.