loss of data on pipes
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > loss of data on pipes




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    loss of data on pipes  
Kamal R. Prasad


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-20-04 10:50 PM

From: Paul Pluzhnikov (ppluzhnikov-nsp@charter.net)
Subject: Re: loss of data on pipes

View this article only
Newsgroups: comp.unix.programmer
Date: 2004-12-16 21:51:53 PST

"Adrian  Wong" <atwong@gmail.com> writes:

> Does this sound right?

>No. It sounds like a bug in your program.



> I didnt think pipes would be "lossy"?

>They aren't.

They aren't lossy -if you mean that they should be writing out all
that they *manage* to read in.

> Shouldnt the child processes printing to
> a pipe be blocked if the pipe is full, i.e. the
> whole setup has it's own throttling mechanism?

>Yes.

The best thing to do is to write() in a loop, till all of the bytes
are sent out. I mean, write() returns the no. of bytes actually
written -which you use to determine how much more needs to be written.

> BTW I am interested in any other solution for
> the mangled output problem besides writing to
> regular files.

>The trivial solution is to use write(2) instead of printf(3) in
>the child output. So long as the buffer you write() is smaller
>then PIPE_BUF (32768 on AIX-5.1), your writes will be atomic and no
>"mangling" will happen.

Some unix'es have an upper limit of 4KB. If you are communicating
small amounts of data between related processes -pipes are indeed the
preferred means. For larger amounts, try shared memory or mmap()'ing a
file wherein the child writes to it, and the parent reads in and
deletes it. Both of these mechanisms will require a synchronization
primitive to coordinate between child & parent.
You may want to post some pseudo code for people to point out the
mistake.

regards
-kamal





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:09 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register