bash 获取 sshd 的 PID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6867669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting PID of sshd
提问by i0exception
I am executing sshd in a bash script using
我正在使用 bash 脚本执行 sshd
$ /usr/sbin/sshd
How do I get the process ID of this sshd that I executed?
如何获取我执行的这个 sshd 的进程 ID?
回答by Jeremy Roman
sshdwill typically write a PID file; by default this is at /var/run/sshd.pid. You can use this to find the process ID of the listening sshdprocess. You should be aware that sshdmay fork several subprocesses as it works, so what you want really depends on what you intend to do with it.
sshd通常会写一个PID文件;默认情况下,这是在/var/run/sshd.pid。您可以使用它来查找侦听sshd进程的进程 ID 。您应该知道,在工作时sshd可能会分叉多个子流程,因此您想要什么实际上取决于您打算用它做什么。
回答by jman
Try this command:
试试这个命令:
ps aux | grep -e /usr/sbin/sshd | grep -v grep | tr -s " " | cut -d " " -f2
or
或者
cat /var/run/sshd.pid

