1 / 17

4061 Session 13 (2/27)

4061 Session 13 (2/27). Today. Pipes and FIFOs. Today’s Objectives. Understand the concept of IPC Understand the purpose of anonymous and named pipes Describe where file descriptors point after system calls to pipe, fork, and dup

Télécharger la présentation

4061 Session 13 (2/27)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4061 Session 13 (2/27)

  2. Today • Pipes and FIFOs

  3. Today’s Objectives • Understand the concept of IPC • Understand the purpose of anonymous and named pipes • Describe where file descriptors point after system calls to pipe, fork, and dup • Write C code that allows parent and child processes to communicate with pipes or FIFOs • Specifically: write a “filter”

  4. Admin • Quiz 2: Nice!

  5. Inter-Process Communication (IPC) • Techniques for the exchange of data between processes or threads

  6. Why IPC?

  7. UNIX IPC • Lots of ways to do it. We’ll talk about some of the classics in 4061. • Today: • Pipes and FIFOs • Later: • Signals, Sockets

  8. Pipes • Aka: anonymous pipes or unnamed pipes • Very simple IPC • Remember bash shell: | • Chain stdout of one process with stdin of another process • E.g.: ps ax | grep java

  9. Pipes: Conceptually

  10. Pipes: Conceptually • One-way channel for information • Write to the input end, read from the output end • Think of a pipe as a buffer in the operating system that you can read from and write to. • If you fill it up, the writer blocks • If it’s empty, the reader blocks

  11. Opening a Pipe • A process issues a command to create a pipe, and receives two file descriptors.

  12. Forking • To communicate with something, fork.

  13. Cleaning Up • Close unused descriptors.

  14. Details • What do the file descriptors point to? • Well, files...but a special type (in pipefs). • So we can still use file-oriented calls, such as read, write, close, etc. • No mount point, so not visible with ls • If you close one end of a pipe, you can’t reopen it

  15. Details • Often implemented as a circular buffer

  16. Shortcut Methods • popen and pclose

  17. FIFOs (a.k.a. Named Pipes) • (first in first out) • File (of type FIFO) in the filesystem. • Access permissions • Kernel structures are set up on open • Multiple processes can write, only one can read • Writes (smaller than the buffer) are atomic

More Related