Am 20.06.2012 17:04, schrieb Ivan Pechorin:
> 2012/6/20 Christian Heimes <[email protected] <mailto:[email protected]>>
>
> You'd have to register all file descriptors in a
> central registry, remove the FDs on close and close() the FDs after
> fork(). That's lots of work but C++ should make it easie
>
>
> Sounds too complex: why not just close() all the FDs >= 3 after fork(),
> before exec*() ?
>
> Linux and all major types of UNIXes have efficient way to do so (without
> iterating up to resource limit).
That approach may (and in the case of a forking webserver will) close
too may file descriptors. Programs use pipes to communicate with their
children or share sockets.
A forking web server may be implemented as:
conn = accept(listening_socket)
child_pid = fork()
if child_pid == 0:
# child process
do_work(conn)
close(conn)
else:
# server process
add_to_waiters(child_pid)
close(conn)
If you closefrom(3) before do_work() then you also close the
communication channel with the client.
Christian
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev