Code Comments
Programming Forum and web based access to our favorite programming groups.On Mar 22, 7:27 pm, David Schwartz <dav...@webmaster.com> wrote:
> On Mar 22, 7:22 am, Sanchit <sanchitgupt...@gmail.com> wrote:
>
>
> Yes, if written by the process that performed the redirect. Other
> processes are not affected.
>
>
> Correct.
>
>
> Yes. Again, only for that process.
>
> DS
Ok...
printf("\nThis is the write end of the pipe:\n");
fflush(stdout);
So now output of printf will not be printed on screen???
So there is no significance of printf here as the test will not be
flushed and it will not be passed to sort also!
Post Follow-up to this messageOn Mar 22, 3:30 pm, Sanchit <sanchitgupt...@gmail.com> wrote:
> On Mar 22, 7:27 pm, David Schwartz <dav...@webmaster.com> wrote:
>
>
>
>
>
>
>
>
> Ok...
>
> printf("\nThis is the write end of the pipe:\n");
> fflush(stdout);
>
> So now output of printf will not be printed on screen???
> So there is no significance of printf here as the test will not be
> flushed and it will not be passed to sort also!
The text "\nThis is the write end of the pipe:\n" will be
written into the pipe. Another process (your second
child, the one that attempts to invoke sort) reads
that text from the pipe. If the sort execs succesfully,
then sort will read that text and print it to its
stdout. Assuming you invoke the command
from a terminal and do not redirect it, that
process's stdout will be the terminal. However,
if sort does not exec succesfully, then your
program's 2nd child will print "\nDummy Text Line\n",
and never read from the pipe, so the message
from the first child is lost (no one ever reads it
from the pipe).
I'm not sure I understand your confusion exactly.
Are you running the program and seeing output
that you do not expect? What exactly is the output
you are getting, and why is it not what you expect.
When I run your original program, I get:
This is the read end of the pipe:
Dummy Text Line
Parent is terminating
Parent is terminating
The fact that "Dummy Text Line" is appearing indicates that
one of the execs failed. (It is the second one, that tries
to exec "/bin/sort" that is failing). The "Parent is terminating"
appears twice because it is printed by both the parent and
the 2nd child (the one that failed to exec "/bin/sort").
The message about the write end of the pipe is lost
when the pipe is destroyed. In other words, the output
I get is exactly what I expect. Is there something there
that you do not expect?
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.