In Linux, is it possible for me to open a socket and pass the socket to another process?
If yes, can you please tell me where I can find an example?
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can, using
sendmsg()with SCM_RIGHTS from one process to another:http://linux.die.net/man/7/unix
That is not the typical usage though. More common is when a process inherits sockets from its parent (after a
fork()). Any file handles (including sockets) not closed will be available to the child process. So the child process inherits the parent’s sockets.A server process that listens for connections is called a daemon. This usually forks on each new connection, spawning a process to handle each new request. An example of the typical daemon is here:
http://www.steve.org.uk/Reference/Unix/faq_8.html#SEC88
Scroll down to void
process().