Lec9 CS604
Lec9 CS604
Systems
Lecture 9
Agenda for Today
Review of previous lecture
UNIX/Linux IPC tools and
associated system calls
UNIX/Linux standard files and
kernel’s mechanism for file access
Use of pipe in a program and at the
command line
Recap of the lecture
May 28, 2024 © Copyright Virtual University of P
akistan
Review of Lecture 8
Interprocess communication (IPC)
Establishlink and use send/recv
Issues about links: establishing links,
link capacity, links per pair of processes,
processes per link, message size, uni-
or bi-directional
Direct communication
Indirect communication
May 28, 2024 © Copyright Virtual University of P
akistan
Review of Lecture 8
Process synchronization
Buffering capacity of a link
P1 P2
Pipe
FIFO
Network
Socket Connection Socket
Computer
May 28, 2024 1 © Copyright Virtual University of P Computer 2
akistan
UNIX/Linux Pipe
Important system calls
open, read, write, close,
pipe
open: Open or create a file
read: Read from a pipe
write: Write data to a pipe
close: Close/destroy a pipe
pipe: Create a pipe for IPC
May 28, 2024 © Copyright Virtual University of P
akistan
open System Call
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
OPEN_MAX — 1
May 28, 2024 © Copyright Virtual University of P
akistan
Standard Descriptors
in UNIX/Linux
Three files are automatically
opened for every process for the
process to read its input from and
send its output and error messages
to. These files are called standard
files: standard input, standard
output, and standard error.
May 28, 2024 © Copyright Virtual University of P
akistan
Standard Descriptors
in UNIX/Linux
By default, standard files are
attached to the terminal on which a
process runs
Descriptors for standard files are
known as standard file descriptors.
Standard input: 0 (keyboard)
Standard output: 1 (display screen)
Standard error: 2 (display screen)
May 28, 2024 © Copyright Virtual University of P
akistan
pipe() Call
int pipe (int pipedes[2]);
Call fails
At least two slots not empty in the
PPFDT—too many files or pipe open
in the process
Buffer space not available in the
kernel
File table is full
May 28, 2024 © Copyright Virtual University of P
akistan
UNIX/Linux Pipe
Important characteristics of a pipe
Used for communication between
related processes
Used as half-duplex channel
Bounded buffer
Maximum data written is PIPE_BUF
(defined in <sys/param.h> in UNIX
and in <linux/param.h> in Linux)—
5120 and 4096, respectively
May 28, 2024 © Copyright Virtual University of P
akistan
Example
parent child
fork
P P
Read Write
end end
cat Display
pipe grep
Screen