Not elegant, but you could try this:
ps -wweo pid,args | grep gnome | grep -v grep
That will give you AT LEAST one line of output. Each line will be the process id number followed by one space, followed by the exact and full command string that started the process. You can probably tell which (assuming there is more than one) process is the gnome session and kill it this:
kill NUMBER
or if that complains about permissions (but I don't think it will)
sudo kill NUMBER
where NUMBER is the process id number that the ps command showed you.
If this happens a lot, you can change the second grep so that it looks for an exact match on the entire command string so that it shows only the one process you want to kill. That will be the string following the process id number on the line corresponding to the gnome session in the output of
ps -wweo pid,args | grep gnome | grep -v grep
I can't tell you what it will be because I don't use gnome and I'm not certain every gnome system would use exactly the same string anyway. There may be some options that vary. Put that string in a script that extracts the process number and kills it. Like this:
#!/bin/bash
PID_to_kill=$(ps -wweo pid,args | grep "ENTIRE COMMAND STRING GNOME IS STARTED WITH" | grep -v grep | cut -d' ' -f1)
kill $PID_to_kill
By using the entire command string, you remove any possibility of killing some process you really didn't want to kill, just because it had "gnome" as part of the command string that started it.
Name the script something easy to remember like "killgnome". Put it in a directory on your path. "/usr/local/bin/" would be a fairly conventional place. Make it executable. Invoke it by entering its name in a terminal or run box.
This will log you out and take you back to your "display manager" (the gui login dialog) if you have one. If you're not running a default setup and have eschewed a display manager (they are really totally unnecessary) it stops X also, leaving you a login prompt. Or at least that's the way it works with Openbox. Probably the way they all work.
pgrep gnome
,pkill gnome
– muru May 18 '17 at 05:39