1 / 27

ch06: UNIX Special Files

ch06: UNIX Special Files. Ju, Hong Taek Computer Network Lab. Keimyung University juht@kmu.ac.kr Rm: 1228, Tel: 580-5234. Objectives. Learn about interprocess communication Experiment with client-server interactions Explore pipes and redirections Use device control to set parameters

chelsey
Download Presentation

ch06: UNIX Special Files

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. ch06: UNIX Special Files Ju, Hong Taek Computer Network Lab. Keimyung University juht@kmu.ac.kr Rm: 1228, Tel: 580-5234

  2. Objectives • Learn about interprocess communication • Experiment with client-server interactions • Explore pipes and redirections • Use device control to set parameters • Understand how UNIX achieves device independence

  3. 6.1 Pipes • The capacity to communicate is essential for processes that cooperate to solve a problem • Pipe is a the simplest UNIX interprocess communication mechanism • Pipe system call • Creates a communication buffer that caller can access through the file descriptors fildes[0], and fildes[1] • The data written to fildes[1] can be read from fildes[0] on a first-in-first-out basis • Returns 0, if successful • Returns -1 and sets errno, if unsuccessful #include <unistd.h> int pipe(int fildes[2]);

  4. A pipe has no external or permanent name • Used only by the process that created it and by descendants • Unidirectional communication buffer • When a process calls read on a pipe • Returns immediately if the pipe is not empty • Blocks until something is written if the pipe is empty • Return 0 if no process has the pipe open for writing

  5. 6.2 Pipelines • Redirection allow programs that are written as filters to be used generally ex) ls –l | sort –n +4 [2] sort [1] [0] pipe [1] ls [0] [2]

  6. [0] [1] [2] parent [4] [3] pipe [3] [4] child [2] [0] [1] After the fork

  7. [1] [2] parent [4] [0] [3] pipe [3] [1] [4] child [2] [0] After both dup2

  8. [1] [2] parent [0] pipe [1] child [2] [0] After both close

  9. 6.3 FIFO • Pipes are temporarily • Disappear when no process has them open • FIFO • Named pipe: persist special file • Creates a new FIFO special file • Return 0 if successful • Return -1 if unsuccessful and set errno • The unlink function is used to removes FIFO #include <sys/sat.h> int mkfifo(const char *path, not_t mode)

  10. 6.4 Pipes and the Client-Server Model • The client-server model is a standard pattern for process interaction • Client: requests a service • Server: reply a message for the request. • Two named pipes are used • A request pipe • A response pipe

  11. when multiple clients make request. Can the server replies be ready to the right client? Is it possible for a client to block another client request?

  12. 6.5 Terminal Control • Many special files represent devices with characteristics that are platform dependent • However, terminal control was thought to be essential on all systems • The stty command reports or sets terminal I/O characteristics • Speed, size (row, column), echo, • Retrieve the attributes by tcgetattr • Set the parameters by tcsetattr #include <termios.h> int tcgetattr( int fildes, struct termios *termios_p); int tcsetattr( int fildes, int optional_actions, const struct termios *termio_p);

More Related