operating systems - cs604 power point slides lecture 10
TRANSCRIPT
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
1/20
Operating
SystemsLecture 10
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
2/20
Agenda for Today
Review of previous lecture Input, output, and error redirection in
UNIX/LinuxFIFOs in UNIX/Linux
Use of FIFOs in a program and at the
command line
Recap of lecture
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
3/20
Review of Lecture 9
UNIX/Linux I! tools and associated
s"stem calls
UNIX/Linux standard files and#ernel$s mechanism for file access
Use of pipe in a program and at the
command line
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
4/20
Input, Output, Error
Redirection
%ou can use the Linux redirectionfeatures to detach the default files
from stdin, stdout, and stderr andattach other files with them&
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
5/20
Input Redirection
Input Redirection:
command < input-file
command 0< input-filePurpose:'etach #e"(oard from stdin
and attach )input*file$ to it,
i&e&, )command$ reads inputfrom )input*file$ and not
#e"(oard
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
6/20
Input Redirection
$ cat < Phones
[ contents of Phones ]$ grep Nauman < Phones
[ output of grep ]
$
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
7/20
Output Redirection
Output Redirection:
command > output-file
command 1> output-file
Purpose:'etach the displa" screen
from stdout and attach
)output*file$ to it, i&e&,
)command$ sends output to
)output*file$ and not the
displa" screen
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
8/20
$ cat > Phones
[ your input ]
$ grep Ali Phones > Aliphones
[ output of grep ]
$ find ! -name foo -print > foolog
[ error messages ]
$
Output Redirection
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
9/20
Error Redirection
Error Redirection:
command "> error-file
Purpose:'etach the displa" screenfrom stderr and attach )error*
file$ to it, i&e&, error messages
are sent to )error*file$ and notthe displa" screen
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
10/20
$ find ! -name foo -print "> errors
[ output of the find command ]
$ ls -l foo "> errorlog[ output of the find command ]
$ cat errorlog
ls: foo: No such file or directory
$ find # -name ls -print "> #de$#null/bin/ls
$
Error Redirection
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
11/20
UNI!Linu" #I#Os
I! for communication (etweenrelated or unrelated processes on a
computer
+
UNIX/Linux -"stem
FIFO
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
12/20
UNI!Linu" #I#Os
. file t"pe in UNIX
!reated with mknod()or
mkfifo()s"stem call or ("
mkfifocommand
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
13/20
UNI!Linu" #I#Os
Unli#e a pipe, a FIFO must (e
opened (efore using it for
communication
. write to a FIFO that no process
has opened for reading results in a-II0 signal
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
14/20
UNI!Linu" #I#Os
1hen the last process to write to a
FIFO closes it, an 0OF is sent to
the reader
2ultiple processes can write to a
FIFO atomic writes to preventinterleaving of multiple writes
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
15/20
UNI!Linu" #I#Os
3wo common uses of FIFOs In client-server applications, FIFOs
are used to pass data between a
server process and clientprocesses
Used by shell commands to passdata from one shell pipeline to
another, without creating temporary
files
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
16/20
$%ient&Server
$ommunication wit'
#I#Os
client-1 client*4
server
well-known
FIFO
clientFIFO
. . .
readrequest
send reply
readresponsereadresponse
send reply
send
request
send
request
clientFIFO
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
17/20
$reating #I#Os
mknods"stem call
esigned to create special
!device" files
mkfifo!ommand
mkfifo! li(rar" call
Invo#es mknodsystem call
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
18/20
$ommand Line Use of
#I#Os
prog1
prog2
prog3
infile
$m%fifo fifo1
$prog& < fifo1 '
$prog1 < infile ( tee fifo1 ( prog"[ Output ]
$
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
19/20
$ommand Line Use of
#I#Os$man ls > lsdat
$cat < fifo1 ( grep ls ( )c -l '
[] !"#$sort < lsdat ( tee fifo1 ( )c -l
%!#
$
wc *l
infile
fifo+
wc *lipe
sort tee
grep ipe
-
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 10
20/20
Review of previous lectureInput, output, and error redirection
in UNIX/LinuxFIFOs in UNIX/Linux
Use of FIFOs at the command lineRecap of lecture
Recap of Lecture