Exit graphical X session and getting back to TTY

If I start a graphical session (usually Unity Desktop, sometimes XFCE, but a general approach is appreciated) from a TTY using startx, how can I exit this GUI again to get back to my TTY console without logging out?

I tried pkill init which seemed to do what I want, but is this the right way to go? Is the TTY session afterwards in an equal state to before startx or are there any traces left? And preferably the solution should not force running applications to terminate, but quit them gracefully...


Edit:

I started a Unity Desktop session with startx $(which unity) and then ran in a terminal emulator gnome-session-quit with all possible argument combinations, but it did nothing and always failed with the error message below:

** (gnome-session-quit:3968): WARNING **: Failed to call logout: 
GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: 
The name org.gnome.SessionManager was not provided by any .service files

Solution 1:

killall xinit 

works ok. Not sure you're going to find a generic way to gracefully close all possible sessions.

For some reason if I start a unity session from TTY, and then run

unity

in a terminal, it seems to close it fairly gracefully.