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

loss of data on pipes
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

Report this thread to moderator Post Follow-up to this message
Old Post
Kamal R. Prasad
12-20-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
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 08:04 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.