0% found this document useful (0 votes)
22 views17 pages

CS312 Lec 14

The document discusses pipes and FIFOs in Linux system programming. It covers creating and using pipes between processes, bidirectional communication with pipes, and emulating shell commands using pipes. Named pipes or FIFOs are introduced as allowing communication between unrelated processes using file paths. Examples show FIFO usage and the mkfifo system call for creating FIFOs.
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)
22 views17 pages

CS312 Lec 14

The document discusses pipes and FIFOs in Linux system programming. It covers creating and using pipes between processes, bidirectional communication with pipes, and emulating shell commands using pipes. Named pipes or FIFOs are introduced as allowing communication between unrelated processes using file paths. Examples show FIFO usage and the mkfifo system call for creating FIFOs.
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/ 17

SYSTEM

PROGRAMMING
LECTURE # 14
PIPES-II
Course Code: CS 312
Course Instructor: Dr. Sarah Iqbal

1
AGENDA FOR TODAY

 Creating and using pipes in C Program


 Bidirectional Communication using Pipes
 Emulate the shell command $ cat <filename> | wc
 Emulate the shell command $ man ls | grep ls | wc
 Introduction to UNIX Named Pipes
 Illustration showing the working of FIFO

2
USE OF PIPE BETWEEN TWO RELATED PROCESSES

Reader

3
USE OF PIPE BETWEEN TWO RELATED PROCESSES

4
5
BIDIRECTIONAL COMM USING PIPES

6
BIDIRECTIONAL COMM USING PIPES

7
SIMULATING SHELL COMMAND: CAT FILE.TXT | WC

wc

fd[0] fd[1] fd[0] fd[1]

8
SIMULATING SHELL COMMAND: CAT FILE.TXT | WC

9
SIMULATING SHELL COMMAND: MAN LS | GREP LS | WC

fd2[0]

10
SIMULATING SHELL COMMAND: MAN LS | GREP LS | WC

11
INTRODUCTION TO FIFOS

 Pipes have no names, and their biggest disadvantage is that they can be
only used between processes that have a parent process in common
(ignoring descriptor passing)
 UNIX FIFO is similar to a pipe, as it is a one way (half duplex) flow of data. But
unlike pipes a FIFO has a path name associated with it allowing unrelated
processes to access a single pipe
 FIFOs/named pipes are used for communication between related or
unrelated processes executing on the same machine
 A FIFO is created by one process and can be opened by multiple processes
for reading or writing. When processes are reading or writing data via FIFO,
kernel passes all data internally without writing it to the file system. Thus a FIFO
file has no contents on the file system; the file system entry merely serves as a
reference point so that processes can access the pipe using a name in the
file system
12
USE OF FIFO BETWEEN UNRELATED PROCESSES

13
MKFIFO() LIBRARY CALL

 Makes a FIFO special file with name pathname. The second argument mode
specifies the FIFO’s permissions. It is modified by the process’s umask in the
usual way
 Once you have created a FIFO, any process can open it for reading or
writing, in the same way as an ordinary file. Opening a FIFO for reading
normally blocks until some other process opens the same FIFO for writing, and
vice versa

14
MKFIFO() LIBRARY CALL FAILS

 Parent directory does not allow write permission


 Path name already exists
 Path name points outside accessible address space
 Path name too long
 Insufficient kernel memory

15
COMMUNICATION USING FIFO

16
READING & REFERENCES

 The Linux Programming Interface by Michael KerrisK


Chapter 44: PIPES and FIFOS

17

You might also like