From: Hossein Mobahi <hmobahi@yahoo.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Problem with read() and named pipe (FIFO) (pipe not disk)
Date: Tue, 17 Aug 2004 03:55:04 -0700 (PDT) [thread overview]
Message-ID: <20040817105504.31840.qmail@web12706.mail.yahoo.com> (raw)
In-Reply-To: <412179C2.5010003@sancharnet.in>
Hello
The problem is not "\n", but buffered I/O used by
standard IO library. I head that sometimes "\n"
flushes the buffer, but it did not (as I am
experiencing now).
You did not have any problem, because you were
directly reading from a file. If you were reading from
STDIN_FILENO, you would not get your characters when
using "./prg1 | ./prg2" where prg1 is:
main() { printf("TEST\n"); for (;;); }
and prg2 is:
main() { read(STDIN_FILENO, buf, 1000); printf
("%s\n",buf) ; }
The solution that I know is using
write(STDOUT_FILENO,....) instead of printf because it
does not buffer. However, I do not have access to the
source code of prg1, and I must somehow make prg1
flush its standard I/O buffer from outside.
--Hossein
--- joy <gracecott@sancharnet.in> wrote:
> Funny. I have used read() to get 2 characters out of
> a binary file with
> no "\n"'s
> and it never behaved like this. Also the man page
> make sno mention of
> this either.
> Did you try this out? How about fread/fwrite?
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
next prev parent reply other threads:[~2004-08-17 10:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-16 14:47 Problem with read() and named pipe (FIFO) Hossein Mobahi
2004-08-16 14:57 ` Henry Margies
2004-08-17 10:58 ` Problem with read() and named pipe (FIFO) (fflush or fsync) Hossein Mobahi
2004-08-17 3:21 ` Problem with read() and named pipe (FIFO) joy
2004-08-17 10:55 ` Hossein Mobahi [this message]
2004-08-17 17:58 ` Problem with read() and named pipe (FIFO) (pipe not disk) joy
2004-08-17 19:24 ` Hossein Mobahi
2004-08-17 19:25 ` Hossein Mobahi
-- strict thread matches above, loose matches on Subject: below --
2004-08-17 19:25 Hossein Mobahi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040817105504.31840.qmail@web12706.mail.yahoo.com \
--to=hmobahi@yahoo.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).