February 8, 2006
Coverage:
[USP]
Chapter 6
Last Editor Example from Last Class
- graphically describe the situation after a text editor, which
makes a backup of each files it opens, changes a file with a symbolic
link to it
- how can we change our editor so that a symbolic or
hard link to a file it modifies always reference the new file?
- use O_WRONLY and O_TRUNC flags
- causes same inode to be used
Simple (Unnamed) Pipes
- a process communication buffer
- basic ingredient for IPC (interprocess communication) in UNIX
- data written to filedes[1] can be read
from filedes[0] using FIFO
- created with pipe function
- read blocks until something is written to the pipe
- can be used as a synchronization mechanism
- can be used to create a barrier
- not very useful for a single process
- only usable by a process, who calls fork and its descendants
Setting up Pipelines in C
- grep cats pets > _text
- wc -l < num_cats
- grep cats pets | wc -l
- ps -A | grep grep
- traditionally, but perhaps non-intuitively, the command to the right of the
pipe symbol (|) is the parent of that to the left of it in the
code
- blocking nature of read and write synchronize the
processes
- use pipe and dup2 functions in concert to setup a
pipeline
- illustrated several graphic (octopus-looking) depictions of this
process
- graphic depiction of the changes to the file descriptor table as before
and after various function calls
Implementing ls -l | sort -n +4
- unifies many concepts we have learned
- process creation and image swapping
- input/output
- interprocess communication
- why return only error conditions?
Introduced Named Pipes (or FIFOs)
- pipes are temporary, FIFOs area permanent (until you unlink)
- useful when the processes communicating were not
created with fork
- created with mkfifo
- function call and UNIX command
- resulting file
contains p as the character to left of its file permission list
in ls -l output
- beauty of UNIX: unified file access interface
- regular files
- FIFOs
- terminals
- leads to a simple client-server model