Linux 单分支守护进程。如何重新获取控制终端?

发布于 2025-01-17 14:18:00 字数 247 浏览 3 评论 0原文

每个人都说守护程序不应该有控制终端。 双叉方法是双架守护程序永远不会获得控制终端的正确方法,因为它不是会话负责人。

但是,如果我们使用使用setSID()创建一个单叉守护程序,将所有FDS关闭,将FD 0〜2重定向到 /dev /null,但仍然是会话领导者。

那么它如何重新召集控制终端?为了看到它,我该怎么办? 我只想测试它真正获得控制终端。

当我使用ioctl和tiocsctty时,它永远不会成功,因为没有任何有效的FD作为参数。

Everyone says that daemon should not have a controlling terminal.
And double-fork method is the correct way that a double-forked daemon will never acquire a controlling terminal since it's not a session leader.

However, if we create a single fork daemon with using setsid(), close all fds, redirect fd 0~2 to /dev/null, but still the daemon is a session leader.

Then how can it reacquire a controlling terminal? What can i do in order to see it?
I just want to test it really acquires a controlling terminal or not.

When i used ioctl and TIOCSCTTY, it never succeeds since there is no any valid fd to pass as a parameter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文