0% found this document useful (0 votes)
100 views

Exercise 6a. Inter Process Communication - Pipe Date

This document discusses inter-process communication (IPC) using pipes in Linux. It explains that pipes allow communication between the parent and child processes which have separate address spaces. The parent creates a pipe using pipe(), then forks a child process. Both processes can then read from and write to the pipe using the file descriptors. Two pipes are needed for full duplex communication, with the parent writing to pipe1 and reading from pipe2, while the child does the opposite. Questions ask about pipe operation, characteristics, and alternatives for IPC like named pipes.

Uploaded by

ALKESH KUMRAWAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Exercise 6a. Inter Process Communication - Pipe Date

This document discusses inter-process communication (IPC) using pipes in Linux. It explains that pipes allow communication between the parent and child processes which have separate address spaces. The parent creates a pipe using pipe(), then forks a child process. Both processes can then read from and write to the pipe using the file descriptors. Two pipes are needed for full duplex communication, with the parent writing to pipe1 and reading from pipe2, while the child does the opposite. Questions ask about pipe operation, characteristics, and alternatives for IPC like named pipes.

Uploaded by

ALKESH KUMRAWAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Exercise 6a.

INTER PROCESS COMMUNICATION – Pipe()

Date:

Question: Write a Program to create a child process and establish communication between parent and
child using pipes.

Aim:

Prerequisites : pipe(), read(),write(),fork()

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

// Create a pipe using pipe() with integer file descriptors fd[2].

// Check the return value of Pipe() for pipe error; if no errors proceed with the step 3.
// create a child process use fork()

Check for fork() error ; if no errors proceed otherwise exit;

If child region

// use read() with appropriate file descriptor for reading from pipe

Print the message read from the pipe.

// parent portion

Use write() with appropriate file descriptors to write the message in the pipe.

end

Questions:

1. What is the basic mode of operation in pipes?

2. Why the pipe is not a permanent fixture?

3. What are the characteristics of a pipe in Linux/Unix ?

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

Date of Completion: Signature

Result :
Exercise 6b INTERPROCESS COMMUNICATION : Two Pipes

Date:

Question: Create 2 pipes for IPC between parent and child processes.

Aim:

Prerequisites : pipe(), read(), write(),fork().

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:

{ parent should send a message “ Hello” to child using pipe1.

Child receiving should respond with “fine” using pipe2 }

Create two pipes as pipe(fd1[2]) – pipe1, pipe(fd2[2]) – pipe2;

Create a child process : fork()

Child process

// read the message from pipe1 with read() system call

Print the message received.

// Reply the message in pipe2 using write() system call

}
// parent process

write the message in pipe1 using write() system call

read the reply message from pipe2 sent by the child process using read () system call.

End.

Questions :

1. What are the restrictions in using pipe system call.

2. What is a NAMED pipe? Why it is used in LINUX.

3. Which alternatives can be choosen for IPC (a) Pipe (b) NAMED Pipes.

Sl No: Assessment Process Description Mark(s)

1 Documentation/Procedure(2)

2 Program(5)
3 Program Execution and viva (3)

Total(10)

Remarks

Date of Completion: Signature

Result :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy