Understanding Linux Pipes, FIFOs, and Their Limits

linux pipes and fifos l.w
1 / 9
Embed
Share

Explore the concepts of Linux pipes, FIFOs (named pipes), and their limitations in inter-process communication. Learn about pipe semantics, FIFO creation, handling, atomicity, and support for multiple readers and writers in the operating system environment.

  • Linux
  • Inter-process communication
  • FIFOs
  • Pipe semantics
  • Operating systems

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Linux Pipes and FIFOs David Ferry, Chris Gill, Marion Sudvarg, James Orr CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63130 1

  2. Pipes Shell pipelines are a common way to move data between programs, e.g.: cat filename | grep search_string Linux provides pipe() system call to allow direct inter-process communication 2 CSE 422S Operating Systems Organization

  3. Linuxs Pipes The Linux pipe() system call: Allows anonymous (un- named) communication Is unidirectional Produces / consumes data through file syscalls write() and read() Data stored in kernel via pipefs in virtual filesystem See /fs/pipe.c for implementation Process A Write FD Pipe Imp. Read FD Process B 3 CSE 422S Operating Systems Organization

  4. Pipe() Semantics Pipes are only usable between related processes: 1) pipe() creates a read and write descriptor 2) Process forks FDs duplicated across fork() FDs preserved across exec() 3) Reader deletes write FD, writer deletes read FD 4) Writer writes, reader reads Write FD Process A Read FD fork() Write FD Process B Read FD 4 CSE 422S Operating Systems Organization

  5. FIFOs (Named Pipes) Variant to pipes: FIFOs created with mkfifo() library function mknod() is deprecated Handle to FIFO exists as a regular file Read and written like regular file Data is stored in kernel (not disk) Allows non-related processes to communicate Must be open at both ends before reading or writing 5 CSE 422S Operating Systems Organization

  6. Pipe and FIFO Limits Atomicity: I/O is atomic for data quantities less than PIPE_BUF Typical: PIPE_BUF = 4096 bytes Write capacity: Typically 64K Writers block or fail if pipe is full Polling vs. Blocking: Readers may block or fail based on flags set during pipe creation 6 CSE 422S Operating Systems Organization

  7. Multiple Readers and Writers Both pipes and FIFOs support multiple readers and writers But, pipes typically one-reader, one-writer Readers consume data Multiple readers must use synchronization outside of pipe/FIFO if read order must be guaranteed Writes longer than PIPE_BUF from multiple writers may be interleaved CSE 422S Operating Systems Organization 7

  8. FIFOs vs. Files Even though FIFOs have a handle in the regular file system, they are not files! Files backed by a real filesystem FIFOs not backed Files have no atomicity guarantee FIFOs must be opened for reading and writing before either may occur Files have no practical capacity limit 8 CSE 422S Operating Systems Organization

  9. Pipe and FIFO Paradigms Linux pipes and FIFOs are useful to implement key design patterns and idioms: Producer / Consumer Process A Pipe Process B Process A Client / Server Process B FIFO Process D Process C Pipe Active Object Process A Process B Pipe 9 CSE 422S Operating Systems Organization

Related


More Related Content