Question: Write a C program that creates 3 processes ( one parent and two children ) . The processes will relay information to each other in
Write a C program that creates processes one parent and two children The processes will relay information to each other in following fashion:
The first process parent reads a text file inputtxt line by line.
The second process reads from the first pipe and reverse letters Capital to small and small to
capital
The third process reads from the second pipe and outputs to a file egoutputtxt
Please complete the missing parts in the provided skeleton code and dont change any other parts. Also, create
a text file, which contains several text lines. The file will be used as an input for your program. Lastly, please highlight what code you added in another color so I can see what additions you made.
#include
#include
#include
#include
#include
#define READEND
#define WRITEEND
int mainint argc, char argv
declare pipes
int fd fd;
pidt pid;
if pipefd pipefd
fprintfstderr "Pipe failed";
return ;
pid fork;
if pid
fprintfstderr "Fork Failed";
return ;
if pid Parent process
closefdREADEND;
closefdWRITEEND;
FILE fp fopeninputtxtr;
if fp NULL
fprintfstderr "Failed to open file
;
exit;
char lineBUFSIZ;
while fgetsline BUFSIZ, fp
writefdWRITEEND line, strlenline;
memsetline BUFSIZ;
readfdREADEND line, BUFSIZ;
printfs line;
fclosefp;
closefdWRITEEND;
closefdREADEND;
else Child process
pid fork;
if pid Second process
closefdWRITEEND;
closefdREADEND;
char lineBUFSIZ;
while readfdREADEND line, BUFSIZ
for int i ; i strlenline; i
Change lower to upper and upper to lower cases
write code here
writefdWRITEEND line, strlenline;
memsetline BUFSIZ;
closefdREADEND;
closefdWRITEEND;
else Third process
Close unused pipes
write code here
FILE fp fopenoutputtxtw;
char lineBUFSIZ;
while readfdREADEND line, BUFSIZ
prints to the output.txt file
write code here
fclosefp;
closefdREADEND;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
