NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#define BUFFER_SIZE 50

int main(){
// We use two pipes
// First pipe to send input string from parent
// Second pipe to send concatenated string from child

int fd1[2]; // Used to store two ends of first pipe
int fd2[2]; // Used to store two ends of second pipe

char child_msg1[100];
char child_msg2[100];

pid_t p;

if (pipe(fd1)==-1)
{
printf(stderr, "Pipe Failed" );
return 1;
}
if (pipe(fd2)==-1)
{
printf(stderr, "Pipe Failed" );
return 1;
}

char parent_msg[] = "Hello! Child";
p = fork();

if (p < 0)
{
printf(stderr, "fork Failed" );
return 1;
}

// Parent process
else if (p > 0)
{

close(fd1[0]); // Close reading end of first pipe

// Write input string and close writing end of first
// pipe.
write(fd1[1], parent_msg, strlen(parent_msg)+1);
close(fd1[1]);

// Wait for child to send a string
wait(NULL);

close(fd2[1]); // Close writing end of second pipe

// Read string from child, print it and close
// reading end.
read(fd2[0], child_msg1, 100);
printf("Child message: %sn", child_msg1);
close(fd2[0]);
}

// child process
else
{
close(fd1[1]); // Close writing end of first pipe

// Read a string using first pipe
char child_msg[]="hello parent";
read(fd1[0], child_msg2, 100);
printf("Parent message: %sn", child_msg2);


// Close both reading ends
close(fd1[0]);
close(fd2[0]);

// Write concatenated string and close writing end
write(fd2[1], child_msg, strlen(child_msg)+1);
close(fd2[1]);

exit(0);
}
}



     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.