LinuxQuestions.org
Latest LQ Deal: Linux Power User 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-17-2010, 08:31 AM   #1
greplinux
Member
 
Registered: Jun 2007
Posts: 118

Rep: Reputation: 17
Fork behavior while copying file descriptors


Hi all,

I am quite confused about the following description on fork. Could you please explain it ?

--
The child process shall have its own copy of the parent's file descriptors. Each of the child's file descriptors shall refer to the same open file description with the corresponding file descriptor of the parent.
--

For example, I am opening a socket and then fork. Now, does the child have a separate socket or is shares it with the parent. Does I have any impact on using it in child?

Thanks,
 
Old 06-18-2010, 01:36 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Try it.

I believe you'll find that the child has the same descriptor #, and can perform I/O to exactly the same socket.

In the days before threads, that's exactly how a *nix server process created socket handlers.

'Hope that helps .. PSM
 
Old 06-22-2010, 11:34 PM   #3
greplinux
Member
 
Registered: Jun 2007
Posts: 118

Original Poster
Rep: Reputation: 17
Hi paulsm4,

Thanks for responding. :-)

I tried it. But facing problems while doing that. Following is the sequence of steps:

1. Open a RAW socket
2. Fork a child and issue recv call
3. In Parent send

The problem I am facing is, the recv call is not returning. It keeps on waiting. If I reran the program, the recv from the first instance returns and the current recv goes to wait.

Will post the code if you want.

Thanks,
 
  


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
fork() address space copying polymath Programming 7 05-19-2010 02:55 PM
strange (to me) behavior of file permissions when copying file warrob Linux - General 10 10-25-2009 06:13 AM
Different fork/expect behavior in RHEL5 and RHEL4...??? Passions Linux - Software 1 06-24-2009 04:54 PM
Regarding the behavior of function fork() ramkumarv Programming 1 03-08-2006 10:45 PM
unix file descriptors versus c FILE pointers nodger Programming 9 11-25-2004 08:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:09 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