pkill -KILL -u
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 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.
- 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