如何确保用户进程在注销时被杀死?

如何确保用户进程在注销时被杀死?

我的服务器(以及所有 debian 衍生服务器)上的注销问题不会杀死所有用户进程。

我似乎明白这样做是出于工作站效率的原因(假设似乎是同一用户此后不久就会登录)。

举个例子,在一个非常受限的帐户上,我得到:

mcon@cinderella:~$ pgrep --list-full -U gamer
3001599 /lib/systemd/systemd --user
3001600 (sd-pam)
3001615 /usr/bin/pipewire
3001616 /usr/bin/pipewire-media-session
3001624 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
3001706 /usr/libexec/gvfsd
3001711 /usr/libexec/gvfsd-fuse /run/user/1002/gvfs -f
3001839 /usr/libexec/dconf-service
3001841 /usr/libexec/gvfs-udisks2-volume-monitor
3001852 /usr/libexec/gvfs-gphoto2-volume-monitor
3001860 /usr/libexec/gvfs-goa-volume-monitor
3001888 /usr/libexec/goa-daemon
3001906 /usr/libexec/goa-identity-service
3001908 /usr/libexec/gvfs-mtp-volume-monitor
3001915 /usr/libexec/gvfs-afc-volume-monitor
3002093 /usr/libexec/evolution-source-registry
3002108 /usr/libexec/gvfsd-trash --spawner :1.9 /org/gtk/gvfs/exec_spaw/0
3002112 /usr/libexec/xdg-desktop-portal
3002120 /usr/libexec/xdg-document-portal
3002124 /usr/libexec/xdg-permission-store
3002132 fusermount3 -o rw,nosuid,nodev,fsname=portal,auto_unmount,subtype=portal -- /run/user/1002/doc
3002150 /usr/libexec/evolution-calendar-factory
3002162 /usr/libexec/gvfsd-metadata
3002176 /usr/libexec/evolution-addressbook-factory
3002227 /usr/libexec/bluetooth/obexd
3002924 /usr/bin/python3 /usr/share/system-config-printer/applet.py
3827100 /usr/bin/gnome-keyring-daemon --start --foreground --components=secrets

gamer这是在用户注销后以及其他用户(包括我自己)使用该系统之后花费(许多)小时的时间。

我见过这个问题但这不适用于我的情况:我这样做不是nohup希望阻止用户通过或显式启动长时间运行的进程screen,而只是杀死所有“无用”的系统任务。

我尝试设置[Login]->KillUserProcesses=yes/etc/systemd/logind.conf显然没有任何改变。

请注意,所有这些进程对于每个登录过的用户都保持活动状态(当然是自上次重新启动以来)。

我如何摆脱所有这些过程?真的需要运行一些cron脚本来杀死它们吗?如果是这样:如何将“明确需要”的后台进程与系统垃圾分开?

PS:我知道 StackExchange 政策是“每个操作一个问号”,但这些实际上是同一问题的各个方面。

答案1

重新启动或sudo systemctl daemon-reexec. daemon-reload 仅重新加载单元,因此它不起作用。

相关内容