Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error...
-
Upload
jonas-dalton -
Category
Documents
-
view
220 -
download
0
Transcript of Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error...
![Page 1: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/1.jpg)
Operating Systems
Lecture 10
![Page 2: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/2.jpg)
Agenda for Today Review of previous lecture Input, output, and error redirection in
UNIX/Linux FIFOs in UNIX/Linux Use of FIFOs in a program and at the
command line Recap of lecture
![Page 3: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/3.jpg)
Review of Lecture 9
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
![Page 4: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/4.jpg)
Input, Output, Error Redirection
You can use the Linux redirection features to detach the default files from stdin, stdout, and stderr and attach other files with them.
![Page 5: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/5.jpg)
Input Redirection
Input Redirection: command < input-file command 0< input-file Purpose: Detach keyboard from stdin
and attach ‘input-file’ to it, i.e., ‘command’ reads input from ‘input-file’ and not keyboard
![Page 6: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/6.jpg)
Input Redirection
$ cat < Phones[ contents of Phones ]$ grep “Nauman” < Phones[ output of grep ]$
![Page 7: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/7.jpg)
Output Redirection Output Redirection: command > output-file command 1> output-file Purpose: Detach the display screen
from stdout and attach ‘output-file’ to it, i.e., ‘command’ sends output to ‘output-file’ and not the display screen
![Page 8: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/8.jpg)
$ cat > Phones[ your input ]<Ctrl-D>$ grep “Ali” Phones > Ali.phones[ output of grep ]$ find ~ -name foo -print > foo.log[ error messages ]$
Output Redirection
![Page 9: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/9.jpg)
Error Redirection
Error Redirection: command 2> error-file Purpose: Detach the display screen
from stderr and attach ‘error- file’ to it, i.e., error messages are sent to ‘error-file’ and not the display screen
![Page 10: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/10.jpg)
$ find ~ -name foo -print 2> errors[ output of the find command ]$ ls -l foo 2> error.log[ output of the find command ]$ cat error.logls: foo: No such file or directory$ find / -name ls -print 2> /dev/null /bin/ls$
Error Redirection
![Page 11: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/11.jpg)
UNIX/Linux FIFOs IPC for communication between
related or unrelated processes on a computer
P1 P2
UNIX/Linux System
FIFO
![Page 12: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/12.jpg)
UNIX/Linux FIFOs
A file type in UNIX Created with mknod() or mkfifo() system call or by mkfifo command
![Page 13: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/13.jpg)
UNIX/Linux FIFOs
Unlike a pipe, a FIFO must be opened before using it for communication
A write to a FIFO that no process has opened for reading results in a SIGPIPE signal
![Page 14: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/14.jpg)
UNIX/Linux FIFOs
When the last process to write to a FIFO closes it, an EOF is sent to the reader
Multiple processes can write to a FIFO atomic writes to prevent interleaving of multiple writes
![Page 15: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/15.jpg)
UNIX/Linux FIFOs Two common uses of FIFOs
In client-server applications, FIFOs are used to pass data between a server process and client processes
Used by shell commands to pass data from one shell pipeline to another, without creating temporary files
![Page 16: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/16.jpg)
Client-Server Communication with
FIFOs
client-1 client-K
server
well-known FIFO
client FIFO
. . .
read request
send reply
read response read response
send reply
send request
send request
client FIFO
![Page 17: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/17.jpg)
Creating FIFOs
mknod system call Designed to create special (device) files
mkfifo Commandmkfifo C library call
Invokes mknod system call
![Page 18: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/18.jpg)
Command Line Use of FIFOs
prog1
prog2
prog3
infile
$ mkfifo fifo1$ prog3 < fifo1 &$ prog1 < infile | tee fifo1 | prog2[ Output ]$
![Page 19: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/19.jpg)
Command Line Use of FIFOs
$ man ls > ls.dat$ cat < fifo1 | grep ls | wc -l &[1] 21108$ sort < ls.dat | tee fifo1 | wc -l 31 528$
wc -l
infile
fifo1
wc -l Pipe
sort tee
grep Pipe
![Page 20: Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.](https://reader034.fdocuments.net/reader034/viewer/2022051401/5697bf791a28abf838c8233e/html5/thumbnails/20.jpg)
Review of previous lectureInput, output, and error redirection
in UNIX/LinuxFIFOs in UNIX/LinuxUse of FIFOs at the command lineRecap of lecture
Recap of Lecture