How to copy the file description when forking instead of sharing?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.