Pau*_*aul 34
您可以通过 dbus 向 KDE 发送注销命令,它应该(如果可以)终止会话。
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
Run Code Online (Sandbox Code Playgroud)
dbus 是一个消息系统,让应用程序相互通信,qdbus命令是一个实用程序,用于向应用程序发送 dbus 消息。
应用程序向 dbus 注册,而ksmserverKDE的部分是会话管理器——它负责管理谁登录。
因此,我们将消息发送到ksmserver该/KSMServer接口,并告诉它退出。我们发送的消息与您单击桌面上的注销图标时发送给 KSM 的消息完全相同。
三个零是参数,可以改变我们正在执行的注销类型:
第一个参数:
第二个参数:
第三个参数是“when”参数,但不清楚它的影响是什么。
接受的答案是特定于 KDE5 的解决方案,更通用的方法是
loginctl list-sessions
loginctl terminate-session <id>
Run Code Online (Sandbox Code Playgroud)
或者
loginctl terminate-user <username>
Run Code Online (Sandbox Code Playgroud)
还有更多可能的命令:
Session Commands:
list-sessions List sessions
session-status [ID...] Show session status
show-session [ID...] Show properties of sessions or the manager
activate [ID] Activate a session
lock-session [ID...] Screen lock one or more sessions
unlock-session [ID...] Screen unlock one or more sessions
lock-sessions Screen lock all current sessions
unlock-sessions Screen unlock all current sessions
terminate-session ID... Terminate one or more sessions
kill-session ID... Send signal to processes of a session
User Commands:
list-users List users
user-status [USER...] Show user status
show-user [USER...] Show properties of users or the manager
enable-linger [USER...] Enable linger state of one or more users
disable-linger [USER...] Disable linger state of one or more users
terminate-user USER... Terminate all sessions of one or more users
kill-user USER... Send signal to processes of a user
Seat Commands:
list-seats List seats
seat-status [NAME...] Show seat status
show-seat [NAME...] Show properties of seats or the manager
attach NAME DEVICE... Attach one or more devices to a seat
flush-devices Flush all device associations
terminate-seat NAME... Terminate all sessions on one or more seats
Run Code Online (Sandbox Code Playgroud)