pipes in windows and linux

14
PIPES A pipe in computing is way of communication between more than one process .Pipe strictly follows the Inter Process Communication. Pipes were the one of the first mechanism in early UNIX systems.It provides one of the simplest way of communication between different process

Upload: junaid-lodhi

Post on 16-Aug-2015

78 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Pipes in Windows and Linux

PIPESA pipe in computing is way of communication between more

than one process .Pipe strictly follows the Inter Process Communication.

Pipes were the one of the first mechanism in early UNIX systems.It provides one of the simplest way of communication

between different process

Page 2: Pipes in Windows and Linux

General View of Pipe

Page 3: Pipes in Windows and Linux

Types of Pipes

• Ordinary Pipes

• Named Pipes

Ordinary Pipes:

The Ordinary pipe in Operating Systems allows the two procedures to communicate in a standard way: the procedure writes on the one end (the write end) and reads on the consumer side or another end (the read-end). As a result, ordinary pipes are unidirectional, allowing only one-way communication as shown in a figure.

Page 4: Pipes in Windows and Linux

Ordinary Pipe

Page 5: Pipes in Windows and Linux

Ordinary Pipes in Unix System

#define BUFFER_SIZE 25

#define READ_END 0 // fd[0] is the read-end of the pipe

#define WRITE_END 1 //fd[1] is the write-end

int main(void)

{

char write_msg[BUFFER_SIZE]

char read_msg[BUFFER_SIZE];

int fd[2];

pid_t pid;

Page 6: Pipes in Windows and Linux

Example Continued

• I* create the pipe *I

• if (pipe(fd) == -1) {

• fprintf(stderr,"Pipe failed");

• return 1;

• }

• I* fork a child process *I

• pid = fork();

Page 7: Pipes in Windows and Linux

• if (pid < 0) { I* error occurred *I

• fprintf(stderr, "Fork Failed");

• return 1;

• }

• if (pid > 0) { I* parent process *I

• }

• I* close the unused end of the pipe *I

• close(fd[READ_END]);

Page 8: Pipes in Windows and Linux

• I* write to the pipe *I

• write(fd[WRITE_END], write_msg, strlen(write_msg)+1);

• I* close the write end of the pipe *I

• close(fd[WRITE_END]);

• else { I* child process *I

• }

Page 9: Pipes in Windows and Linux

Example Continued

• I* close the unused end of the pipe *I

• close(fd[WRITE_END]);

• I* read from the pipe *I

• read(fd[READ_END], read_msg, BUFFER_SIZE);

• printf ("read %s", read_msg) ;

• I* close the write end of the pipe *I

• close(fd[READ_END]); }

• return 0; }

Page 10: Pipes in Windows and Linux

In Windows

• Ordinary pipes on Windows systems are termed anonymous pipes.

• the pipe is created by using CreatePipe() function

• Functionality, they are unidirectional.

• Readfile() and Writefile() functions are used for reading and writing to the file.

Point of significance:

Note that ordinary pipes require a parent-child relationship between computing processes in both UNIX and Windows systems. This means that pipes can be used only for communication between processes on the same machine.

Page 11: Pipes in Windows and Linux

Named pipes

Page 12: Pipes in Windows and Linux

• Communication can be bi-directional

• no parent-child relationship is required between process

• More than two process can communicate with each other a time

• named pipes exist after completion and termination of all the processes

Page 13: Pipes in Windows and Linux

In Unix

Name pipes referred to as FIFO (first in first out) in UNIX systems.

Once they created.

They appear as typical files in the file systems.

A FIFO is created with the mkfifo() system call and manipulated with open(), read(), write() and close() system calls.

FIFO supports two-way communication, only half-duplex transmission is permitted.

Page 14: Pipes in Windows and Linux

In Windows

• Much richer communication mechanism between processes rather than UNIX systems

• Full-duplex communication is allowed in Windows named pipe

• The communication may run from either different sides or from the same side of the pipe at a same time

• Name pipe is created with CreateNamedPipe() function, and a client can connect the named pipe using ConnectNamedPipe(). Communication over the named pipe can be accomplished using the ReadFile() and WriteFile() functions

POINT OF SIGNIFICANCE:

Windows provides the facility of the communication between processed residing on different machines.