Networking Forums

Networking Forums > Computer Networking > Linux Networking > Fork and Closing Open Sockets

Reply
Thread Tools Display Modes

Fork and Closing Open Sockets

 
 
Beagle
Guest
Posts: n/a

 
      11-17-2008, 04:45 PM
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
 
Reply With Quote
 
 
 
 
Beagle
Guest
Posts: n/a

 
      11-17-2008, 05:07 PM
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:
> 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


 
Reply With Quote
 
Beagle
Guest
Posts: n/a

 
      11-17-2008, 07:03 PM
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(..);
....
}


>
> 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.


 
Reply With Quote
 
Robert Nichols
Guest
Posts: n/a

 
      11-18-2008, 04:29 AM
In article <0e6064ac-c720-4f02-8253-(E-Mail Removed)>,
Beagle <(E-Mail Removed)> 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"
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fork and execve to inherit [non root]parent process's capabilities hieswarmcaquest Linux Networking 0 05-27-2011 03:26 PM
Maximum number of open sockets Wagner Windows Networking 3 03-09-2006 01:43 PM
Parental Controls - Closing open ports =?Utf-8?B?bGFqbWU=?= Broadband Hardware 0 02-12-2006 05:24 PM
Closing Open Files Jay Gray Windows Networking 2 03-28-2005 04:51 PM
Closing ports Antonio Grasso Windows Networking 1 11-24-2003 12:15 PM



1 2 3 4 5 6 7 8 9 10 11