LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2010, 09:34 AM   #1
kickarzt
LQ Newbie
 
Registered: Feb 2010
Posts: 18

Rep: Reputation: 0
File descriptors with pipes


------File descriptors with pipes----
Can someone help me with this three situations, what would happen?

a) a process open the same file twice and read through two file descriptors
b) a process does fork and both parent- and child-processes read parallell
c) two processes opens and read from same file.
 
Old 06-04-2010, 10:18 AM   #2
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
I think that as long as this is read-only access, no issues should aries.... in all three cases, the file will be correctly read.
 
Old 06-05-2010, 05:20 AM   #3
kickarzt
LQ Newbie
 
Registered: Feb 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Are u really sure about that? Two processes open and reads at the same time, why should I have to close other pipe fd, etc if that weren´t a problem then? You say, as long as it´s only read access, why´s that?
 
Old 06-05-2010, 08:17 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Write access is more complicated. For instance, process A can open file X for writing and start writing content in the file.
While A is doing that, process B may open same file for write (rather than append) or even delete the file. This is then typically done after A is done writing, so A may not perform its write properly.

Disk caching in particular will even help to make parallell reads more optimal.
All 3 indeed should work just fine. But note that the file part that is read can be different.

As some food for thought:
in scenario a), how does the process open the 2nd file descriptor? By a simple fopen? Or a dup() of the first file descriptor?
 
Old 06-05-2010, 06:20 PM   #5
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
Normally you have to close the pipe just to clear and release resources. Let's say, you open 1,000 times the same file for read only, that's a lot of resources to allocate and might require memory and make your programs sluggish. However, as long as for data consistency, no problems should arise.

Do notice that if you attempt to write on the file, you'd have issues as for data consistency, because you can not longer rely on the order that the processes are operating.

I hope this helps

Alejandro
 
Old 06-06-2010, 08:35 AM   #6
kickarzt
LQ Newbie
 
Registered: Feb 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks for the answers, I think I get it know ;-)
Reading ok, but be aware of writing..
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing file descriptors nikin Linux - Newbie 2 06-05-2008 05:16 AM
File Descriptors matsko Linux - Software 2 04-24-2008 12:45 PM
Increasing File Descriptors Geoffrey_Firmin Slackware 5 04-21-2008 10:48 AM
file descriptors node047 Linux - Newbie 1 03-29-2005 06:47 AM
unix file descriptors versus c FILE pointers nodger Programming 9 11-25-2004 08:02 AM


All times are GMT -5. The time now is 11:03 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration