开发者

Getting PID of sshd

开发者 https://www.devze.com 2023-03-23 13:07 出处:网络
I开发者_运维百科 am executing sshd in a bash script using $ /usr/sbin/sshd How do I get the process ID of this sshd that I executed? sshd will typically write a PID file; by default this is at /va

I开发者_运维百科 am executing sshd in a bash script using

$ /usr/sbin/sshd

How do I get the process ID of this sshd that I executed?


sshd will 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 sshd process. You should be aware that sshd may fork several subprocesses as it works, so what you want really depends on what you intend to do with it.


Try this command:

ps aux | grep -e /usr/sbin/sshd | grep -v grep | tr -s " " | cut -d " " -f2

or

cat /var/run/sshd.pid
0

精彩评论

暂无评论...
验证码 换一张
取 消