Question: How do you cleanly logout of X using command line?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Question: How do you cleanly logout of X using command line?
Hi everyone,
I am using RH 7.2 with gnome for all the computers under network.
Here is the situation:
I am logged onto 2 computers, both running X.
I have an ssh terminal session from one computer onto the other.
In the ssh session, I want to logout of X cleanly of the other computer.
Bascially, what I need to know is what the command is for logging out of X. Normally, I would just press the logout button or press control-alt-backspace. However, since I want to do this from an ssh session, I need to know how to do it with commandl line.
Right now, the command I am using is "killall X"
Obviously, this isn't really isn't really doing things clean and nice.
Why isn't a kill a clean way to stop a process? The kill will send it a SIGTERM which gives the process a chance to clean things up before it stops running. I'm sure X has a proper signal handler and does the appropriate thing when it gets a SIGTERM.
Mik, how about supressing all the error messages? I think alot of n00bs have a huge problem seeing all the error message when they kill something, especially X. Is there a way to suppress those messages associated with killing X?
If you don't know what messages I am referring to I'll post some when I get home
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771
Rep:
hmm.. I usually use killall X. init 3 may work if you are in another runlevel, but if you use a text login and use xinit, telinit will exit saying you're already at runlevel 3. Well you can always take it to runlevel 1 as root and then bring it back to 3 or 5, whatever it was, but that would disrupt other daemons/services. Even if you do that, the kernel will first send out a TERM signal and then a KILL( to the bad boys who still didnt TERMinate ) to all processes created in the current runlevel before you switch. So the X server will get a TERM either way. As far as I've seen killall X doesnt hurt.
Well I havent found a way to gracefully exit a program unless I started it in from the same terminal. Because even if you want to tell the program to gracefully exit from a different terminal, there is no way to communicate your intentions to it. So all control goes through the process management tools ( murder murder )
well a kill -HUP or such will ask a program to quit, it will not just delete the process or anything, it is certainly graceful enough.
as for running init 3... besides the fact that it's a horrendously daft idea IT will kill the process anyway. that's all the thing will actually do. on runlevel 5 all you get is a continually respawning login manager process, and changing out of that runlevel will simply tell that process to die. just as inelegant, and certainly more longwinded and bizarre.
That's cool then Thanks for the clarification everyone!
So would there be a list of numbers to look at for someone like me to know what a kill signal is? What I mean is when you kill something with -15 or -9 what the 15 and 9 are?
I am glad to hear that other people are also using killall X. It is true that I haven't yet run into a problem with killall X. It seems to work cleanly enough.
However, the people I work for would still like it to be done better if possible.
My question is this.
When you are in X and you want to logout, you just go to the menu and press the logout button.
When you press the logout button, it must call some kind of script or executable to log you out.
What is this script or executable that this logout button calls?
I have tried to find out what this is, but the logout button doesn't let me see the properties and what command it is calling.
I was wondering if anyone knows this script/exe command?
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771
Rep:
tzeng,
Assuming that you too use runlevel 3 and 'startx' to start the X server, that is what I do and I'm most familiar with.
startx is a bash script that (may be customized by the distro guys to change the default options) to call xinit with a set of options. As soon as xinit is called it forks an X server, it looks for a ~/.xinitrc ( if there isn't one, it will fall back to the system default /etc/X11/xinit/xinitrc or some such ). and executes it.
xinitrc is just a shell-script that calls a bunch of x clients of your choice ( xterm, netscape, windowmanager etc). If you have noticed, there is an & at the end of every line but the last one in an xinitrc script.
Now xinit leaves the X server child alone for the time being and probably calls something like a waitpid() ( IMHO) on the client processes started from xinitrc, so that the parent blocks until that particular child terminates. Your X session lasts as long as this script executes. So, obviously, if you want more than one client program to be started, you'll have to run the first few in the background so that the control will return to the non-interactive shell and more may be started. The last one to start is usually the window manager, which is a special client which can decorate and control the rest of the clients, support a wallpaper by repainting ( it may use the services of another prog here ) that part of the window that gets exposed when a window gets moved/resized etc. You cannot start more than one window manager or the X server will complain and kill the second one. As soon as the window manager exits, .xinitrc finishes executing and xinit is notified. It kills the X server and quits.
The best way to illustrate this behaviour is to create a .xinitrc with just an xterm in it. As soon as you QUIT the xterm by pressing Ctrl-D or use logout, the X session ends. Then create one with xterm & and an xterm and see that as long as you keep the last client running, xinit keeps the server alive.
So when you rightclick and choose exit ( or something of the sort ) on a window manager, you are actually requesting it to quit ( and thereby end xinitrc and thereby kill your X server implicitly ) by executing a hard-wired execution path coded into the window manager. It is like using :wq in vim. As I said before, unless you started a particular client program from the *same* terminal/console as you are now, there is no way to request the process to exit gracefully.
Also, whether you use killall or exit the WM, the X server ends up with a TERM. It is your client programs ( such as an open word processor/editor with unsaved data) that you need to be worried about killing. Hope I'm making sense.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.