-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |