by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :) Computer Engineering Tips - Computer Engineering news and articles - Pipes Computer Engineering Tips - Computer Engineering news and articles - Pipes
  Home arrow Operating Systems arrow Fundamentals arrow Pipes
Computer Engineering Tips - Computer Engineering news and articles | _DATE_FORMAT_LC
 
 
Main Menu
Home
News
Algorithms
Artificial Intelligence
Bioinformatics
Computer Graphics
Computer Networks
Computer Organization
Computer Security
Data Mining
Data Structures
Database Systems
Distributed Computing
Internet
Operating Systems
Parallel Computing
Programming Languages
Publications
Robotics
Software Engineering
Other Articles


Partners

All Partners

 
 
 
Pipes _CMN_EMAIL
_USER_RATING: / 0
_VOTE_POOR_VOTE_BEST 

What are Pipes?

Pipes are communication devices for unidirectional communication. It consists of two ends namely, the “read end” and “write end”. Pipes read data in the same order as it is written to them. Pipes can be used for communicating between parent and child process or between two threads in a single process.

In a shell, a symbol | creates a pipe. Eg. This shell command causes the shell to produce two child processes, one for ls and one for less:

% ls | less

The shell also creates a pipe connecting the standard output of the ls subprocess with the standard input of the less process. The filename listed by ls are sent to ls in exactly the same order as if they were sent directly to the terminal.

A pipe’s data capacity is limited. If data is being written at a faster rate as compared to the speed of the reader, and if pipe’s capacity gets full then the writer process blocks until more capacity becomes available. Thus, the pipe automatically synchronizes the two processes.

Creating Pipes:

To create the pipe, invoke the pipe command. Supply an integer array of size two. The call to pipe stores the reading file descriptor in array position 0 and the writing file descriptor in position 1.

Eg.,

int p_fds[2];
int r_fd;
int w_fd;
pipe(p_fds);
r_fd = p_fds[0];
w_fd  = p_fds[1];

Data written to the file descriptor r_fd can be read back from w_fd.

Communication between Parent and Child Processes:

Pipes create valid file descriptors within that process and its children. Unrelated processes can be passed a process’s file descriptors, however, file descriptors gets copied

when the process calls fork.Thus, pipes can connect only related processes.

If you use a command ls | less, two forks occur; one fork caters the ls child process and one for the less child process. Both of these processes can communicate using a pipe as they inherit the pipe file descriptors. To have unrelated process communicate, a FIFO can instead be used.

Redirecting the standard Input, Output and Error streams:

Frequently, you will want to create a child process and set up one end of a pipe as its standard input or standard output. Using the dup2 call you can equate one file descriptor with another.

For example, in order to redirect the process’s standard input to a file descriptor fdp, users can write:

dup2(fdp,STDIN_FILENO);

STDIN_FILENO here represents the standard input’s file, having value 0. The standard input closes gets closed due to the call and then reopens as a duplicate of fd so that the two may be used interchangeably. Same file status flags and file position is shared by equated file descriptors. Thus characters read from fd are not reread from standard input.

When a command needs to be ignorant of its source:

The ignorance of a command about its source and destination can be essential for the programmers in many ways. For example, the wc command in the following code displays the total size of all C programs:

wc –c *.c
2078	string.c
231	array.c
………
1994	robot.c
214	swap.c
940101    total

The display shows the total usage at 940101 bytes, but it also shows the usage for each file. We are not interested in individual statistics this time, what we need is a single figure representing the total size. To able to do that, you must make wc ignorant of its input source. You can do that by feeding the concatenated output stream of all these files to wc –c as its input:

$ cat *.c | wc –c
940101

Since wc acts on a stream this time, it displays a single figure. We can use this command sequence as a control command in a shell script to determine whether the files will fit in a floppy diskette.

 
 Sponsored Links

_USER_RATING: / 0
_VOTE_POOR_VOTE_BEST 
_ITEM_PREVIOUS   _ITEM_NEXT
 
       
         
     
 
Advertisement
 
   

Copyright 2005 - 2006 Science Tips Team. All rights reserved.

Nanotechnology Development Blog