Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Unable to understand behavior of pipe
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!


Report this thread to moderator Post Follow-up to this message
Old Post
Sanchit
03-23-08 12:13 AM


Re: Unable to understand behavior of pipe
On 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?

Report this thread to moderator Post Follow-up to this message
Old Post
William Pursell
03-23-08 09:43 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): « 1 [2]
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:26 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.