www.smartbusinesschoices.com

Leading Business and Technology,
News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

Fork and Closing Open Sockets
   Smart Linux Business Choices! - the Best of UseNet Postings! Forum Index -> Linux Networking  
View previous topic :: View next topic  
Author Message
Beagle
Guest






PostPosted: Mon Nov 17, 2008 5:45 pm    Post subject: Fork and Closing Open Sockets Reply with quote

Folks,

The server pid accepts network connections until the 'host' connection
exits, then all clients exit (e.g. all sockets are closed). A special
case is a recorder shell based client that starts after the first
client connects, but when the host exits, it waits for the shell to
exit before closing the rest of the connections, even though I see in
the logs the server closes all connections.

Thanks,
BEA
Back to top
Beagle
Guest






PostPosted: Mon Nov 17, 2008 6:07 pm    Post subject: Re: Fork and Closing Open Sockets Reply with quote

Whoops, did say what my question was... I basically want to start a
background process that doesn't inherit any of the open file
descriptors of the parent. Is there a way to do that?

On Nov 17, 9:45 am, Beagle <beagle...@hotmail.com> wrote:
Quote:
Folks,

The server pid accepts network connections until the 'host' connection
exits, then all clients exit (e.g. all sockets are closed). A special
case is a recorder shell based client that starts after the first
client connects, but when the host exits, it waits for the shell to
exit before closing the rest of the connections, even though I see in
the logs the server closes all connections.

Thanks,
BEA
Back to top
Beagle
Guest






PostPosted: Mon Nov 17, 2008 8:03 pm    Post subject: Re: Fork and Closing Open Sockets Reply with quote

On Nov 17, 10:07 am, Beagle <beagle...@hotmail.com> wrote:
Quote:
Whoops, did "not" say what my question was... I basically want to start a
background process that doesn't inherit any of the open file
descriptors of the parent. Is there a way to do that?

After fork, in the child, iterating thru the list of open fds and
closing them worked.

int pid = fork()
if (pid == 0) {
....
for (int i = 0; i < OPEN_FDS; i++)
close(i);

execl(..);
....
}


Quote:

On Nov 17, 9:45 am, Beagle <beagle...@hotmail.com> wrote:

Folks,

The server pid accepts network connections until the 'host' connection
exits, then all clients exit (e.g. all sockets are closed). A special
case is a recorder shell based client that starts after the first
client connects, but when the host exits, it waits for the shell to
exit before closing the rest of the connections, even though I see in
the logs the server closes all connections.
Back to top
Robert Nichols
Guest






PostPosted: Tue Nov 18, 2008 5:29 am    Post subject: Re: Fork and Closing Open Sockets Reply with quote

In article <0e6064ac-c720-4f02-8253-84901d1f74dd@40g2000prx.googlegroups.com>,
Beagle <beagle197@hotmail.com> wrote:
:On Nov 17, 10:07 am, Beagle <beagle...@hotmail.com> wrote:
:> Whoops, did "not" say what my question was... I basically want to start a
:> background process that doesn't inherit any of the open file
:> descriptors of the parent. Is there a way to do that?
:
:After fork, in the child, iterating thru the list of open fds and
:closing them worked.
:
:int pid = fork()
:if (pid == 0) {
:...
:for (int i = 0; i < OPEN_FDS; i++)
: close(i);
:
:execl(..);

The alternative is to control this in the parent process by using
fcntl(2) to set the close-on-exec (FD_CLOEXEC) flag on file descriptors
you don't want the child process to see.

--
Bob Nichols AT comcast.net I am "RNichols42"
Back to top
Display posts from previous:   
   Smart Linux Business Choices! - the Best of UseNet Postings! Forum Index -> Linux Networking  
Page 1 of 1
All times are GMT

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum