Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main()
- {
- int pipefd[2], n;
- char input = 0;
- char buffer[100] = {0};
- char outpipe[100] = {0};
- if(pipe(pipefd) < 0) {
- printf("FAILED TO MAKE PIPESn");
- return;
- }
- printf("Starting up, read fd = %d, write fd = %dn", pipefd[0],pipefd[1]);
- do {
- //print menu options (send message, get message, get my fd,
- // set a fd to talk to, quit)
- // if "send a message":
- {
- printf("What would you like to send?n");
- fgets(buffer, 100, stdin);
- write(pipefd[1], buffer, strlen(buffer));
- }
- //else if "read a message":
- {
- if(open(outpipe, 0) < 0)
- printf("Couldn't open the pipe!n");
- else {
- n = read(outpipe, buffer, 100);
- printf("I got a read of %d bytesnIt was %sn",n, buffer);
- close(outpipe);
- }
- }
- //else if "get my file descriptor":
- printf("My fd tag is: /proc/%d/fd/%dn", (int)getpid(), pipefd[0]);
- //else if "set a file descriptor to talk to":
- {
- printf("What is the pipe's file descriptor?n");
- fgets(outpipe, 100, stdin);
- n = strlen(outpipe) - 1;
- outpipe[n] = '