UNIX File I/O and Pipes: File Descriptors, open(), pipe(), and Implementation in Shell, Slides of Computer Programming

A review of unix file i/o concepts, focusing on file descriptors, open() system call, and pipe() system call. It also covers the implementation of pipes in a shell. Examples and exercises to help understand the concepts.

Typology: Slides

2012/2013

Uploaded on 04/29/2013

parmita
parmita 🇮🇳

4.7

(17)

183 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Review
UNIX file system
File system abstraction
Directories
File descriptors
Unix API Programming Examples and Techniques
Example with direct IO
open, close, fdopen, lseek, unlink
Variable argument list
Docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download UNIX File I/O and Pipes: File Descriptors, open(), pipe(), and Implementation in Shell and more Slides Computer Programming in PDF only on Docsity!

Review

  • UNIX file system
    • File system abstraction
    • Directories
    • File descriptors
  • Unix API Programming Examples and Techniques
    • Example with direct IO
      • open, close, fdopen, lseek, unlink
    • Variable argument list

Review

  • File I/O
    • File descriptors
      • open, creat, close, dup, dup
    • I/O redirection
  • Process management
    • fork, exit, wait, waitpid, execv
  • Pipes
    • Named and unnamed pipes
    • Implementing pipe in a shell

Pipes

• Named pipe ( not our emphasis )

• Unnamed pipe

• Implementing pipe in a shell

Named and unnamed pipes

  • Named pipe ( not our emphasis )
    • Like a file (create a named pipe ( mknod ), open,

read/write)

  • Can be shared by any process
  • Unnamed pipe
  • An unnamed pipe does not associate with any

physical file

  • It can only be shared by related processes

(descendants of a process that creates the

unnamed pipe)

  • Created using system call pipe()

An example for the use of a pipe

  • example3.c
    • Once the processes can communicate

with each other, their execution order can

be controlled

Implementing pipe in shell

  • Example

/usr/bin/ps –ef | /usr/bin/more

  • How does the shell realize this command?
    • Create a process to run ps -ef
    • Create a process to run more
    • Create a pipe from ps -ef to more
      • The standard output of the process to run ps -ef is redirected to a pipe streaming to the process to run more
      • The standard input of the process to run more is redirected to be the pipe from the process running ps –ef
    • See example4.c