Hi!
> I read that
> 1. It is possible for two processes to share/own the same socket
Correct.
> 2. For one process to handover a socket it owns to other process.
>
> Is this really possible, if so how ?
Yes it is. In fact, you might even pass any descriptor (which might
refer to a file, a pipe, a FIFO, a socket...) between processes.
The technic is described in Stevens, Unix Network Programming, Vol 1,
2nd ed, §14.7 (pp381-389)
If you want, we might give you an example how to do this.
> For 1. I can think of forked processes sharing sockets created before
> forking, Is there some other way to do this ?
On linux, yes. You might created a process using clone() with the flag
CLONE_FILES. Doing so, parent and child share the same descriptors, and
operation on a descriptor is visible in both processes. That is if you
close a descriptor in the child, it will be also closed in the parent
(this differs from a forked child: in a forked child, the descriptor
would be only closed in the child).
Cheers,
Loic.
|