🐧 Как узнать PID службы с помощью systemctl

by itisgood

Используйте systemctl, чтобы получить идентификатор процесса для указанной службы.

Версия systemd:

$ systemctl --version
systemd 247 (247.3-1)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=unified

Проверим статус службы ssh.

$ systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-03-14 13:48:08 UTC; 1h 30min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 380 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 384 (sshd)
      Tasks: 1 (limit: 526)
     Memory: 6.1M
        CPU: 118ms
     CGroup: /system.slice/ssh.service
             └─384 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Warning: some journal files were not opened due to insufficient permissions.
$ systemctl show --property MainPID ssh
MainPID=384

$ systemctl show --property MainPID ssh
MainPID=1208
Покажем идентификатор процесса для службы ssh (только значение).
$ ps -f --pid 384
UID          PID    PPID  C STIME TTY          TIME CMD
root         384       1  0 13:48 ?        00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Loading

You may also like

Leave a Comment