CIS 345/CIS 545 Assignment 1 Two-way Inter-process communication Points: 35 Write an inter process communication program

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

CIS 345/CIS 545 Assignment 1 Two-way Inter-process communication Points: 35 Write an inter process communication program

Post by answerhappygod »

CIS 345/CIS 545 Assignment 1 Two-way Inter-process communicationPoints: 35 Write an inter process communication program in Clanguage to exchange message between parent process and childprocess. This Assignment is aimed to learn one-way and two-wayinter-process communication using fork() and pipe()functionalities. This assignment has two parts. 1. Part a) 10points One –way communication using a single pipe Write a programin C that will write and read a message, “I am your Parent –Group#” through the pipe using the parent and the child processes.Algorithm: Step 1 − Create a pipe. Step 2 − Create a child process.Step 3 − Parent process writes to the pipe. Step 4 − Child processretrieves the message from the pipe and writes it to the standardoutput. 2. Part b) 10 points Write a program in C for two-wayinter-process communication where parent process will write amessage and child process will read and will display on the screenusing the first pipe. Child process will write a message and parentprocess will read and will display on the screen using the secondpipe. . Two-way Communication using pipes: Anonymous pipe is aunidirectional communication channel which means either the parentprocess writes and the child process reads or vice-versa but notboth. However, when both the parent and the child want to write andread from the pipes simultaneously, they need to use two pipes fora two-way communication. The steps to achieve two-waycommunication: • Step 1 − Create two pipes. First one is for theparent to write and child to read (call pipe1). Second one is forthe child to write and parent to read (call pipe2). • Step 2 −Create a child process. • Step 3 − Close unwanted ends as only oneend is needed for each communication. • Step 4 − Close unwantedends in the parent process, read end of pipe1 and write end ofpipe2. • Step 5 − Close the unwanted ends in the child process,write end of pipe1 and read end of pipe2. • Step 6 − Perform thecommunication as required. Algorithm • Step 1 − Create pipe1 forthe parent process to write and the child process to read. • Step 2− Create pipe2 for the child process to write and the parentprocess to read. • Step 3 − Close the unwanted ends of the pipefrom the parent and child side. • Step 4 − Parent process to writea message and child process to read and display on the screen. •Step 5 − Child process to write a message and parent process toread and display on the screen. 3. Execution Steps Compilation gccAssignment1bgroup1.c –o Assignment1bgroup1 Execution (ExpectedOutput) In Parent: Writing to pipe 1 – Message is Parent In Child:Reading from pipe 1 – Message is Parent In Child: Writing to pipe 2– Message is Child In Parent: Reading from pipe 2 – Message isChild 4. Submit your assignment through blackboard with thefollowing: a. working code (20 points) b. codeexplanation/documentation (5 points) c. screenshots with timestampto show that your code is working (10 points) 5. Use Fenn Hall lab(FH128) systems or virtual Linux machines to execute the program.6. Mention individual contribution of each member (in percentage).7. Only group leader will submit the assignment via blackboardlink. Help: // Fork() declaration section if(pid==0) { printf("thechild\n" ); } else if(pid>0) { printf("the parent\n"); wait(); }// Sample instructions to close unwanted ends of parent and childprocess for two-way communications using two pipes if (pid != 0) //Parent process { close(pipefd1[0]); // Close the unwanted pipe1read side close(pipefd2[1]); // Close the unwanted pipe2 write side……. else { //child process close(pipefd1[1]); // Close the unwantedpipe1 write side close(pipefd2[0]); // Close the unwanted pipe2read side ……
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply