| View previous topic :: View next topic |
| Author |
Message |
Beagle Guest
|
Posted: Mon Nov 17, 2008 5:45 pm Post subject: Fork and Closing Open Sockets |
|
|
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
|
Posted: Mon Nov 17, 2008 6:07 pm Post subject: Re: Fork and Closing Open Sockets |
|
|
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
|
Posted: Mon Nov 17, 2008 8:03 pm Post subject: Re: Fork and Closing Open Sockets |
|
|
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
|
Posted: Tue Nov 18, 2008 5:29 am Post subject: Re: Fork and Closing Open Sockets |
|
|
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 |
|