LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 07-31-2010, 05:55 PM   #1
qweasd
Member
 
Registered: May 2010
Posts: 338

Rep: Reputation: Disabled
reading from named pipes versus urandom


I am trying to write (in C++) something that behaves similarly to /dev/urandom, but using named pipes. After a lot of cursing I came up with a "server" program that opens a named pipe for reading, then opens it for writing, then starts writing bytes in an infinite loop. This allowed me to meet much of the demand I had for the "server":

1. Since the pipe is always open for reading by at least one process, it never fails with SIGPIPE due to others opening and/or closing it for reading.

2. Many processes can open the pipe and read from it simultaneously, as many as the OS will bear.

But I noticed that when I run two simultaneous readers, they seem to read the same bytes. That is, the "server" writes one stream and both readers get to see the entire stream. As I increased the number of readers (to about 5), the readers started to see different streams (I am guessing that some bytes have enough time to get removed from the pipe while a reader is waiting for its turn). I don't know if it matters, but I have 4 cores.

I have a couple of questions.

Is there any way to prevent the pipe data from being read twice?

Does /dev/urandom have the same behavior, either theoretically or practically? That is, can two processes ever read the same byte from /dev/urandom if they do it simultaneously enough?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Named pipes and C jobless Programming 2 10-21-2008 01:31 PM
Question about reading/writing into a Named Pipes(FIFO) Sathya Programming 21 05-05-2008 08:39 AM
named pipes lamtab Programming 12 12-11-2007 10:44 AM
reading from /dev/urandom in c djgerbavore Programming 5 10-04-2005 12:54 PM
Use of Named Pipes casey0999 Linux - Software 3 08-03-2003 01:21 PM


All times are GMT -5. The time now is 03:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration