Write and run a C program on UNIX that creates four new processes

Write and run a C program on UNIX that creates four new processes

Write and run a C program on UNIX that creates four new processes

Write and run a C program on UNIX that creates four new processes: A, B, C,and D. When the original process creates the new processes, it passes themall the same pipe that they can use to send data to the original process,which will serve as a logging process, displaying each line it receives alongwith a time stamp. A pipeline is to exist between A and B, another betweenB and C, and another between B and D. Including the shared pipe back to thelogging process and these three pipes (A-B, B-C, B-D) there are four pipes.Process A generates 10 records consisting of the letter C or D (picked atrandom for each record) along with the record number (1 byte ASCII) issuedsequentially from 0 to 9 and sends it to process B. Process A also sends alog message something like: A sent process B ‘D1’ to the logging process.Process B reads from the pipe connecting it to A. For each record it reads,it will send it to the process indicated by the first character, along withsending an appropriate log message to the logging process. For example, ifit receives a message containing ‘C2’, it sends the message to process C.After sending the logging message, process B waits one second.Process C reads its pipe and for each message received it sends the loggingprocess an appropriate message.Process D reads its pipe and for each message received it sends the loggingprocess an appropriate message. Process D then waits 5 seconds after everytime it receives a message.The logging process should terminate when it receives 30 messages, which is10 messages from A to B, a total of 10 messages from either B to C or B to D,and then a total of 10 more messages from either C or D indicating receipt.Implement some way to terminate the other processes at appropriate times.Here is pseudocode for the pipe program:Main programInclude header filesInitialize variablesCreate log pipeCreate A-B pipeCreate B-C pipeCreate B-D pipeFork process ALoop 10 timesCreate 10 records, starting with ‘C’ or ‘D’ chosen randomlyfollowed by a number from 0 to 9 issued in sequential orderWrite each record to the A-B pipeWrite a message to the log pipeEnd loopExit process AFork process BLoop 10 timesRead a record from the A-B pipeWrite records starting with ‘C’ to the B-C pipeWrite records starting with ‘D’ to the B-D pipeWrite a message to the log pipeDelay for 1 secondEnd loopExit process BFork process CLoop until no more messagesRead a record from the B-C pipeWrite a message to the log pipeEnd loopExit process CFork process DLoop until no more messagesRead a record from the B-D pipeWrite a message to the log pipeDelay 5 secondsEnd loopExit process DLoop 30 times (Logging process – not forked)Read a message from the log pipeAdd the time to the messagePrint the message to the screenEnd loopKill process A if necessaryKill process B if necessaryKill process C if necessaryKill process D if necessaryEndNote: You don’t need to pass any parameters to the child processes becausethey already have access to all the pipes that were created in main process.

 

CLICK TO ORDER A CUSTOM PAPER

We are the best paper help / essaytyper in the world