Exercise 6a. Inter Process Communication - Pipe Date
Exercise 6a. Inter Process Communication - Pipe Date
Date:
Question: Write a Program to create a child process and establish communication between parent and
child using pipes.
Aim:
Concept :
From the previous exercises 4a,4b and 4c it is understood that the Parent and child processes remain in
separate address spaces.
To have some sort of communication between them, IPC is used. Here, a kernel data structure named
pipe() is used. Initially using a pipe() , a pipe is created. The pipe system call uses 2 int type file
descriptors , for reading and writing messages from it.
A child process is then created using fork(). Since the child process is created after the pipe(), The file
descriptors being a part of pipe , also duplicated in the child address space Hence, the child process and
parent process can access the pipe using the descriptors.
Procedure:
Begin
// Check the return value of Pipe() for pipe error; if no errors proceed with the step 3.
// create a child process use fork()
If child region
// use read() with appropriate file descriptor for reading from pipe
// parent portion
Use write() with appropriate file descriptors to write the message in the pipe.
end
Questions:
4. What happends when a process tries to read an empty pipe() ? Will it wait or end ?
Sl No: Assessment Process Description Mark(s)
1 Documentation/Procedure(2)
2 Program(5)
3 Program Execution and viva (3)
Total(10)
Remarks
Result :
Exercise 6b INTERPROCESS COMMUNICATION : Two Pipes
Date:
Question: Create 2 pipes for IPC between parent and child processes.
Aim:
Concept :
Since, a pipe() behaves in a half duplex mode. To establish communication between parent and
child and vice-versa , Two pipes(pipe1,pipe2) are used. Using a pipe1 a message is sent from
parent to child , the child after receiving the message from pipe1 should respond in pipe2, which in
turn read by the parent process.
Procedure:
Child process
}
// parent process
read the reply message from pipe2 sent by the child process using read () system call.
End.
Questions :
3. Which alternatives can be choosen for IPC (a) Pipe (b) NAMED Pipes.
1 Documentation/Procedure(2)
2 Program(5)
3 Program Execution and viva (3)
Total(10)
Remarks
Result :