A)有没有办法确定导致创建特定进程(在我的示例输出中,进程2738,PA守护程序)的systemd单元?
当然。您可以运行systemctl status <pid>
,systemd将找到包含该PID的单元。例如,在我的系统上,我找到一个dnsmasq
过程:
# ps -fe | grep dnsmasq
nobody 18834 1193 0 Aug25 ? 00:00:10 /usr/sbin/dnsmasq ...
是谁开始的?
# systemctl status 18834
● NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2015-08-25 11:07:40 EDT; 1 day 21h ago
Main PID: 1193 (NetworkManager)
Memory: 1.1M
CGroup: /system.slice/NetworkManager.service
├─ 1193 /usr/sbin/NetworkManager --no-daemon
├─ 1337 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-wlp3s0....
├─18682 /usr/libexec/nm-openvpn-service
├─18792 /usr/sbin/openvpn --remote ovpn-phx2.redhat.com 443 tcp --nobind --dev redhat --de...
└─18834 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --...
我也有一个pulseaudio
过程:
# ps -fe | grep pulseaudio
lars 2948 1 0 Aug25 ? 00:06:20 /usr/bin/pulseaudio --start
运行systemctl status 2948
,我看到:
● session-3.scope - Session 3 of user lars
Loaded: loaded (/run/systemd/system/session-3.scope; static; vendor preset: disabled)
Drop-In: /run/systemd/system/session-3.scope.d
└─50-After-systemd-logind\x2eservice.conf, 50-After-systemd-user-sessions\x2eservice.conf, 50-Description.conf, 50-SendSIGHUP.conf, 50-Slice.conf
Active: active (running) since Tue 2015-08-25 11:09:23 EDT; 1 day 21h ago
CGroup: /user.slice/user-1000.slice/session-3.scope
这告诉我pulseaudio
是从桌面登录会话开始的,而不是通过systemd显式启动的。
systemctl
有一个--property
用于选择单元属性显示的选项,但不幸的是这仅适用于show
没有status
,和show
不带PID的工作。我能想到的最好的方法是:systemctl status -n0 $PID 2>/dev/null | head -n1 | awk '{print $2}'