LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
LinkBack Search this Thread
Old 01-30-2003, 04:37 PM   #1
tzeng865
LQ Newbie
 
Registered: Jan 2003
Posts: 4

Rep: Reputation: 0
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.

Thank you for any help!
 
Old 01-31-2003, 01:47 AM   #2
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,611

Rep: Reputation: 61
You could also try:
init 3

This should drop you back out of X (usually, this depends on how the distro's inits are setup, but I think it'll work for RH 7.2).

And it should be relatively clean, probably a bit nicer than killall X.

Cool
 
Old 01-31-2003, 02:24 AM   #3
Mik
Guru
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Gentoo + LFS
Posts: 1,316

Rep: Reputation: 46
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.
 
Old 01-31-2003, 02:28 AM   #4
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,611

Rep: Reputation: 61
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

Cool
 
Old 01-31-2003, 02:36 AM   #5
nxny
Member
 
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771

Rep: Reputation: 30
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 )
 
Old 01-31-2003, 02:47 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,832

Rep: Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116
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.
 
Old 01-31-2003, 02:58 AM   #7
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,611

Rep: Reputation: 61
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?

Cool
 
Old 01-31-2003, 07:44 AM   #8
sean_pereira
LQ Newbie
 
Registered: Mar 2002
Location: Perth, WA
Distribution: Gentoo, ubuntu, BeatrIX, Knoppix, RedHat <= 9, Solaris 8
Posts: 17

Rep: Reputation: 0
You can use the cmd : kill -l to list out all the kill signals. A look at /usr/include/linux/signal.h would also help
 
Old 01-31-2003, 07:48 AM   #9
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,611

Rep: Reputation: 61
Awesome, thank you!
 
Old 01-31-2003, 07:50 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,832

Rep: Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116
masterc there is a man page for it.. erm..... can't remember, but this has all the relvevant info.
http://www.hmug.org/man/2/sigaction.html
 
Old 01-31-2003, 08:40 AM   #11
Mik
Guru
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Gentoo + LFS
Posts: 1,316

Rep: Reputation: 46
The man page it's in is the following one:

man 7 signal
 
Old 01-31-2003, 10:36 AM   #12
tzeng865
LQ Newbie
 
Registered: Jan 2003
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you everyone for your responses.

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?

Thank you for any suggestions.
 
Old 01-31-2003, 11:45 AM   #13
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,832

Rep: Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116
i'd be very confident that that too is just a signal to X to hang up.
 
Old 01-31-2003, 11:46 AM   #14
nxny
Member
 
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771

Rep: Reputation: 30
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.

HTH

Last edited by nxny; 01-31-2003 at 01:15 PM.
 
Old 01-31-2003, 12:42 PM   #15
chingasman
Member
 
Registered: Dec 2002
Location: Orange County, CA
Distribution: Mandrake 9.0 x2
Posts: 91

Rep: Reputation: 15
jesus
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line question shadoweyez Linux - Software 2 11-18-2005 06:28 PM
Command line question satimis Linux - General 14 06-20-2005 09:46 PM
command line question phonecian Linux - Software 2 10-09-2004 08:36 AM
RHL9.0 hangs when logout/exit command line mellsie25 Linux - Newbie 7 10-17-2003 09:30 PM
command line question... warheros Linux - Newbie 12 06-25-2003 04:34 AM


All times are GMT -5. The time now is 08:40 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration