CS312 Lec 14
CS312 Lec 14
PROGRAMMING
LECTURE # 14
PIPES-II
Course Code: CS 312
Course Instructor: Dr. Sarah Iqbal
1
AGENDA FOR TODAY
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
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
15
COMMUNICATION USING FIFO
16
READING & REFERENCES
17