在Linux中的进程之间传输套接字

在Linux中的进程之间传输套接字

本文介绍了在Linux中的进程之间传输套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux下的进程之间转移套接字的所有权?Windows具有 Socket.DuplicateAndClose 函数,但是有没有办法在Linux上做到这一点?

How can I transfer the ownership of a socket between processes under Linux? Windows has a Socket.DuplicateAndClose function, but is there a way to do this on Linux?

如果有所不同,我想将所有权从父进程转移到子进程,并且在获得套接字时子进程还不会启动,所以我很感兴趣涉及 fork exec 函数系列的解决方案.

If it makes a difference, I would like to transfer the ownership from a parent process to a child process, and the child process won't be started yet at the time I obtain the socket, so I'm open to interesting solutions involving fork and the exec family of functions.

推荐答案

子进程将继承文件描述符.因此,除了在分叉孩子后关闭父级中的套接字之外,您无需执行其他任何操作.

The child process will inherit the file descriptor. So you have nothing to do except closing the socket in the parent after you forked the child.

如果您在子文件中 exec 的另一个可执行文件,则可能要使用特定的参数将文件描述符值通知给它.

If you exec another executable in the child, you may want to inform it of the file descriptor value by using a specific argument.

这篇关于在Linux中的进程之间传输套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:56