Pipes and Named Pipes (FIFO)
Pipes are the classical method of interprocess communication.
# ls –l | more
The symbol | indicates a pipe and the shell in the above example runs the processes ls and more which are linked with a pipe. ls writes data to the pipe and more reads it.
Named pipes otherwise called as the FIFO (First in First Out) is the other variant of pipe.
They can be created like this
# mkfifo pathname
# mkfifo hello
# ls –l hello
prw-r- -r- - 1 temp users 0 Aug 28 10.45 hello |
there are many similarities between the pipes and the FIFO, but the inode specification for the both are more or less the same.
following is the inode specification for the pipe
wait_queue_head_t wait; //wait queue
char * base; //address of the FIFO buffer
unsigned int readers; //no of processes reading at this moment
unsigned int writers; //no of processes writing at this moment
unsigned int waiting_readers; //no of blocked process reading at this moment
unsigned int waiting_writers; //no of blocked processes writing at this moment
unsigned int r_counter; //no of read processes that have opened
unsigned int w_counter; //no of write processes that have opened
The length of the area of the pipe is managed in the i_size field. The system call pipe creates a pipe which involves setting up a temporary inode and allocating a page of memory which is decided by the architecture dependent model.
Opening a FIFO
|For reading||No Writing Processes||Block||Open FIFO|
|Writing Processes||Open FIFO||Open FIFO|
|For Writing||No Reading Processes||Block||Error ENXIO|
|Reading Process||Open FIFO||Open FIFO|
|For Reading and Writing||Open FIFO||Open FIFO|