In modern systemd Linux distros, the answers are all a little too complicated.
The solution is one tool: loginctl
.
In a good shell you even have autocompletion, so make use of Tab to see the options and parameters and it is quite intuitive.
The command to search for is kill-session
.
If you tab, you'll notice each session has an ID, but in my case it also showed the username and TTY (that is the Ctrl+Alt+number you type) and the seat.
Here is how it looks to me, e.g.:
$ loginctl kill-session 10
10 -- 1000 rugk seat0 tty2
You can tab through the sessions to find the correct one.
Otherwise, if that does not work you can find the session ID by running loginctl list-sessions
or just loginctl
. You get something like this:
$ loginctl list-sessions
SESSION UID USER SEAT TTY
10 1000 rugk seat0 tty2
I guess it's quite obvious the first column contains the session ID you need to pass to loginctl kill-session
.
This works very well if the GUI hangs and you need to force-kill it, which seems to be your use case.
If you want that to be explained in a more elaborate way here is how you can kill your own session if the GUI is not responding or you cannot use your keyboard.