如何在没有`master`标识的情况下找到主进程PID?

How to find the main process PID without `master` identification?

如何在没有master识别的情况下找到主进程PID?

在这种情况下:

[root@4d62e42f3cde conf.d]# ps -ef | grep demosoft
root      1700     1  0 08:34 pts/0    00:00:00 grep --color=auto demosoft
root     26814     1  0 Apr12 ?        00:00:00 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26815 26814  0 Apr12 ?        00:01:33 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26816 26814  0 Apr12 ?        00:01:36 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26817 26814  0 Apr12 ?        00:01:35 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26818 26814  0 Apr12 ?        00:01:32 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26819 26814  0 Apr12 ?        00:01:30 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26820 26814  0 Apr12 ?        00:01:29 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26821 26814  0 Apr12 ?        00:01:29 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26822 26814  0 Apr12 ?        00:01:30 demosoft --config=/etc/demosoft/demosoft.conf
demosoft    26823 26814  0 Apr12 ?        00:01:44 demosoft --config=/etc/demosoft/demosoft.conf

我只知道使用命令: ps -ef | grep demosoft | awk '{print }' 获取 PID:

1710
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823

我想向主进程发送 SIGHUP 信号。但是如何?

你知道它是否是 Nginx 进程,我可以通过以下方式发送 SIGHUP 信号:

kill -HUP $(ps -ef | grep nginx | grep master | awk '{print }')

但是demosoft没有master标识

您可以在阅读其文档后安装然后使用 pstree(1) 命令。

您也可以在阅读其文档后使用 top(1), pgrep(1) and pkill(1) 命令。

你可以使用 signal(7) (see also proc(5) and signal-safety(7)) and several syscalls(2) in your C program (maybe also with nftw(3)...) after having read more documentation and Advanced Linux Programming

在大多数 Linux 系统上,您可以访问 /proc/ - 请仔细阅读 proc(5)

您可能想阅读与 systemd(1) and credentials(7) 相关的文档。

我还建议阅读 Nginx. Since it is open source software, you are allowed to download its source code 的文档,然后改进它。

您甚至可以(但这样做存在网络安全风险)编写一些 FastCGI thing to remotely kill(2) processes (or use killpg(2)) thru a web interface, or use libonion to write some webservice doing so, or contribute (in spring or summer 2021) to the RefPerSys 项目来更巧妙地做到这一点