LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2013, 06:00 AM   #1
Simple12
LQ Newbie
 
Registered: Aug 2012
Posts: 16

Rep: Reputation: Disabled
How to copy the file description when forking instead of sharing?


Hi all,
When a process forks, the child will share with its parent the file description(that includes the offset and the file status flag) that was open before the forking.

Is there a way to make the child have its own copy of the file description ?

I need that since I don't want both parent and child to share the same offset of the file; if one process has done a read, I don't want the offset of the file for the second process to be changed.


Thank you
 
Old 04-03-2013, 06:32 AM   #2
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
pread() function may be of interest to you.
 
Old 04-03-2013, 07:08 AM   #3
Simple12
LQ Newbie
 
Registered: Aug 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mina86 View Post
pread() function may be of interest to you.
pread() does not change the offset after the read. I want the offset to be changed independently in each process.
 
Old 04-03-2013, 08:03 AM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Some ideas here
http://stackoverflow.com/questions/1...another-access
 
Old 04-03-2013, 08:23 AM   #5
Simple12
LQ Newbie
 
Registered: Aug 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
I couldn't get how this would help. basically, When the parent forks, I want the child to get the same copy of the open file entry of its parent. meaning if the parent before the fork has done some reads, I want the offset in the child to be the same as just before the fork. after the fork I want each processes to have its own copy of the offset.
 
Old 04-03-2013, 08:30 AM   #6
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by Simple12 View Post
pread() does not change the offset after the read. I want the offset to be changed independently in each process.
Depending what you are doing, you can maintain the offset by yourself.

Quote:
Originally Posted by Simple12 View Post
I couldn't get how this would help. basically, When the parent forks, I want the child to get the same copy of the open file entry of its parent. meaning if the parent before the fork has done some reads, I want the offset in the child to be the same as just before the fork. after the fork I want each processes to have its own copy of the offset.
And your problem is?
Code:
pos = lseek(fd, 0, SEEK_CUR);
reopenFdUsingStackOverflowCode(fd);
lseek(fd, pos, SEEK_SET);
 
Old 04-03-2013, 09:08 AM   #7
Simple12
LQ Newbie
 
Registered: Aug 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mina86 View Post
Depending what you are doing, you can maintain the offset by yourself.


And your problem is?
Code:
pos = lseek(fd, 0, SEEK_CUR);
reopenFdUsingStackOverflowCode(fd);
lseek(fd, pos, SEEK_SET);
Thank you, I got the idea
 
  


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
dnsmasq.lease file + description of its contents vlrk Linux - Server 2 09-22-2011 07:45 AM
zone file description waji Linux - Newbie 3 07-03-2008 05:19 AM
file description apache mjenkins Linux - General 2 04-08-2004 12:32 AM
Copy Winbloze file to Samba Share -Sharing Violation tornadoburn Linux - Software 1 11-25-2003 12:07 AM
How can I open more than 2000 file description at the moment? zhnt Linux - General 2 04-08-2001 08:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:19 PM.

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
Open Source Consulting | Domain Registration