You can send a logout command via dbus to KDE, which should (if it can) terminate the session.
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
dbus is a messaging system that lets applications communicate with each other, and the qdbus
command is a utility for sending dbus messages to applications.
Applications register with dbus, and the ksmserver
part of KDE is the session manager - it looks after who is logged in.
So we are sending a message to ksmserver
to the /KSMServer
interface and telling it to logout. The message we are sending is the exact same message that is sent to KSM when you click on the logout icon on your desktop.
The three zeros are parameters and can alter the type of logout we are doing:
First parameter:
- 0 = Do not wait for confirmation
- 1 = Wait for confirmation (with a 30 second timeout)
Second parameter:
- -1 = Prompt for action, defaulting to shutdown (Only makes sense when waiting for confirmation.)
- 0 = Logout
- 1 = Restart
- 2 = Shutdown
The third parameter is the "when" parameter, but it isn't clear what its impact is.
1
See also How can I safely shutdown/reboot/logout KDE from the command line?
– Reinstate Monica - M. Schröder – 2015-02-07T14:02:08.703@MartinSchröder - ah, good catch - it's essentially the same question. But Paul's answer to this question is more exhaustive that Gilles' answer to the other one. – kostja – 2015-02-07T16:37:59.873