ch06: UNIX Special Files

Preview:

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

ch06: UNIX Special Files

Ju, Hong TaekComputer Network Lab.

Keimyung Universityjuht@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 Understand how UNIX achieves device independe

nce

6.1 Pipes The capacity to communicate is essential for processes t

hat 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]);

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

6.2 Pipelines Redirection allow programs that are

written as filters to be used generallyex) ls –l | sort –n +4

sort

ls

pipe

[0] [2]

[1]

[0] [1]

[2]

parent

child

pipe

[0] [1]

[4]

[3] [4]

[2]

[2]

[3]

[1][0]

After the fork

parent

child

pipe

[0]

[1] [4]

[3] [4]

[2]

[2]

[3]

[1]

[0]

After both dup2

parent

child

pipe

[0]

[1]

[2]

[2]

[1]

[0]

After both close

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)

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

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?

6.5 Terminal Control Many special files represent devices with characteristics t

hat are platform dependent However, terminal control was thought to be essential on

all systems The stty command reports or sets terminal I/O characteristic

s 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);