大网数据广告活动
服务器运维问答

What is the functional difference between `loginctl terminate-session` `loginctl kill-session` and `systemctl stop`

· 52CE 我爱测

I'm having trouble sussing out the differences between these commands, especially around using them with session-c###.scope units. I've tried looking at the man page, and looking through the code a bit but some questions remain. …

问题原文

原帖链接 · Redoubts · CC BY-SA 4.0

I'm having trouble sussing out the differences between these commands, especially around using them with session-c###.scope units. I've tried looking at the man page, and looking through the code a bit but some questions remain.

The man page suggests loginctl kill-session sends a signal to one or all processes in a session. So how is this different from loginctl terminate-session? The man page suggests

This kills all processes of the session and deallocates all resources attached to the session.

but is this much different from kill-session -s SIGKILL?

The problem I'm facing is after doing something like loginctl kill-session c###, the session no longer appears for the user in loginctl session-status or list-sessions, but systemctl status session-c###.scope will show it as abandoned, and the processes appear to remain according to ps. I wonder if loginctl terminate-session would have been better, or even systemctl stop

已采纳解答

原帖链接 · u1686_grawity · CC BY-SA 4.0

loginctl kill-session [--signal=] has exactly the same effect as systemctl kill – both end up calling systemd's KillUnit(signal) via D-Bus on the .scope unit object. (Note that both default to sending a SIGTERM, not SIGKILL.)

Similarly, loginctl terminate-session has mostly the same effect as systemctl stop, both commands will call systemd's StopUnit() via D-Bus. (However, loginctl will explicitly mark the .scope as "abandoned" before trying to stop it, causing systemd to log about any leftover processes.)

A small difference in both cases is that the calls made by loginctl are proxied through the logind daemon, which applies different polkit authorization rules than a direct call to systemd would. (For example, normally non-root users cannot call systemd directly.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-06-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。