A form of IPC (interprocess communication). When fork is used, there is no longer a connection between parent and child, you need IPC to share data between the processes.
- Pipes are local to one machine
- Pipes are one way
popen() is like the system() call. Should only be used for quick and dirty programming. popen is different from system in that system is a blocking call.
pipe() creates two file descriptors (you pass it a 2 element array of file descriptors to make). popen uses pipe, fork, and exec internally. Array element 0 is input. Array element 1 is output.
default file descriptors
0 - Input from keyboard
1 - Output to screen
2 - Output to screen
When you fork a process with file descriptors, the child 'inherits' the file descriptors
Pipes are blocking and are therefore automatically synchronizing.
There should be a 1:1 relationship between pipes (although it is possible to have 1:n... it creates reading problems... pipes are read only once and data is deleted once read)
Using Pipes as STD I/O
dup() and dup2() duplicate the file descriptor with a new fd. You want to
Named Pipes (FIFO) - First in First Out
Can be accessed by any local process
mkfifo() -
IMPORTANT (will lose marks in assignment if we dont do these three things)
- Put FIFO in /tmp
- Use $$.something to make the FIFO unique
- delete the FIFO when finished (unlink)
No comments:
Post a Comment