Question: Rewrite the program as a set of two programs that utilize a named pipe ages in the current folder for IPC and implement the same

Rewrite the program as a set of two programs that utilize a named pipe ages in the current folder for IPC and implement the same function as discussed above.

#include

#include

#include

#include

int main(void)

{

int fd[2], nbytes;

pid_t childpid;

int users = 95;

char mystring[80];

char readbuffer[80];

char digit1,digit2;

digit1 = (char) users%10;

digit2 = (char ) users/10;

mystring[0] = digit1;

mystring[1] = digit2;

printf("%d %d ",mystring[0],mystring[1]);

pipe(fd);

if((childpid = fork()) == -1)

{

perror("fork");

exit(1);

}

if(childpid == 0)

{

/* Child process closes up input side of pipe */

close(fd[0]);

/* Send "string" through the output side of pipe */

write(fd[1], mystring, sizeof(mystring));

exit(0);

}

else

{

/* Parent process closes up output side of pipe */

close(fd[1]);

/* Read in a string from the pipe */

nbytes = read(fd[0], readbuffer, sizeof(readbuffer));

printf("Received string: %d %d ",readbuffer[0],readbuffer[1]);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!