Linux: How does user log out work

4

I'm new with linux. I've searched about how to safely log out other user and found few solution but I want to know how they work internally. I have few questions:
1. pkill -KILL -u {username} Does it just send SIGKILL to every child of init --user? and does it ensure that every child process is safely killed?
2. Can It be done using sending only signals?

P.S I have program which creates init --user for other user, I'm killing using SIGTERM but sometimes compiz crashes. Thats why I'm interesting how should it work properly.

user590536

Posted 2016-05-23T09:56:41.220

Reputation: 71

Answers

3

  1. pkill -KILL -u {username} Does it just send SIGKILL to every child of init --user? and does it ensure that every child process is safely killed?

It sends SIGKILL to all processes owned by the {username} account, regardless of their parent. (Note that "init --user" is somewhat distro-specific.)

However, it's about as far from "safe" as you can go. SIGKILL is the brute force approach which ends all processes without letting them properly shut down and clean up; it's the opposite of "safe."

Many terminal-based programs react to SIGHUP as "line hangup". After a few seconds, the remaining ones can be stopped with SIGTERM. Only then, if you still have leftovers after both SIGHUP and SIGTERM, should you use SIGKILL as the final approach.

  1. Can It be done using sending signals?

Possibly – most programs do understand SIGHUP or SIGTERM. But graphical programs might prefer to be stopped by the session manager, i.e. by gnome-session, using ICE/XSMP (I don't know how this works exactly). In general, the "safest" approach would be to use the desktop environment's logoff command; for example:

gnome-session-quit --logout --force --no-prompt
gnome-session-save --force-logout --silent
qdbus org.kde.ksmserver /KSMServer logout 0 -1 -1
qdbus org.razorqt.session /RazorSession logout
mate-session-save --logout
xfce4-session-logout --logout

user1686

Posted 2016-05-23T09:56:41.220

Reputation: 283 655

Thank you very much. But one more question please. What is the difference between gnome-session-quit and using pkill -KILL - u {username} – user590536 – 2016-05-23T10:21:28.383

gnome-session-quit sends an IPC message to gnome-session, which first announces the logout using XSMP, then exits, letting the display manager shut down the Xorg server. – user1686 – 2016-05-23T10:35:03.803

thanks a lot. One more please :D. So sending SIGTERM to init --user can not be related to compiz crash problem? – user590536 – 2016-05-23T11:05:41.413

and which one is used when linux is normally logging off? – user590536 – 2016-05-23T11:12:23.817