ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
> The output is only passed to Program B once Program A has completed.
Then if Prog A outputs a huge amount of data or if Prog A doesn't stop writing, the pipe will overflow. Or isn't it the case?
/* Simple Prog A */
#include <stdio.h>
#include <unistd.h>
int main()
{
int i = 0;
do {
printf( "i = %d\n", i );
i ++;
usleep(10000);
} while(1);
return 0;
}
At the command line
% progA | grep '0'
gives output from time to time though.
Last edited by Jerry Mcguire; 01-19-2010 at 02:16 AM.
We have seen and used a lot of piping, e.g. % A | B
in which the output of program A is fed to the input of program B.
If I am to write program B, do I simply read stdin? <I really doubt this>
Yes, just read stdin. Until the read-function you use indicates end-of-file (EOF).
Quote:
Originally Posted by Jerry Mcguire
e.g. % ll | grep 'jerry'
grep does know when ll has finished. How?
ll closes his stdout, or if it doesn't close his stdout, the kernel will when ll exits. This makes the pipe send EOF to the reading end (grep), where to code should detect EOF and act accordingly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.