Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Logout from OS X via the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Logout from OS X via the Terminal
Authored by: mkhaw on Feb 22, '05 02:42:40AM

With admin/root privileges you can always type "shutdown", with various optional flags, to kick everyone off with or without in fact shutting down the machine (and if shut down, optionally restart). Read the man page (in Unix-speak, shutdown(8)).

One respondent said "exit" will log you out of a Terminal window, to which a follow-on said "ctrl-d" works too. The difference is "exit" isn't affected by whether your shell has ignoreeof (in tcsh/csh, IGNOREEOF in bash) set, whereas ctrl-d is (although some csh implementations will log you out if you ctrl-d enough times in succession regardless of ignoreeof). Sorry, I don't know how zsh behaves in this regard.



[ Reply to This | # ]
Logout from OS X via the Terminal
Authored by: floh on Feb 22, '05 10:19:21AM

There are basically two diffrenet types of shell invocation. A shell can be a login shell or it can be an interactive shell.
When you are inside a login shell, you have come there through a login - sounds straight forward, doesn't it? - and thus you have to logout to close the shell session via the logout command.
When you are inside an interactive shell, you haven't seen a login prompt anywhere immediately near the shell invocation. So you don't close the shell session with logout - you never logged in for that shell sesseion anyway. You use the exit command.
Whenerver you open a new terminal window in OS X, you are invocating your shell implicitly as an interactive shell. Logout in this circumstance just doesn't make any sense - speaking from a unix standpoint of view. So basically, logout in an interactive shell is an alias to exit. This might be confusing but is a better solution than to implement the keyword goto into the language java just so as to issue an error message.
Remember that in OS X you are logged in in a windowing environment. You have never come to the windowing environment through a console login, using startx or something like that. Your terminal application is just another child of your windowing session, which is itself a child of a graphical login session. For a little child to kill his grandfather by his own hand would be far too much cruelty for such a feeble mind, so logout won't be tampering anywhere up your tasks' heritage chain.
If you now, on the other hand, had come to the windowing environment through startx, returned to the virtual console, pressed ctrl-z, set the windowing session bg and then typed logout ... this would kill your windowing session and log you out completely, at least on this one virtual console. For once or twice in my life with Mac OS X I had hoped for virtual consoles. But what the heck ...
So basically, trying to do a complete logout via keyboard by aliasing the builtin logout command is, as interesting as it might be on first thought, on second thought trying to do it the unix way without getting to know, and understand, that is, the unix way on the first hand; on a unix operating system which does it's best to hide away it's unix heritage.
Sorry for the rumpling. Just some thought from a traveler of platforms.



[ Reply to This | # ]
Logout from OS X via the Terminal
Authored by: derekhed on Feb 22, '05 11:43:22AM

Excellent post!

Thank you.



[ Reply to This | # ]
new Terminal windows run "login shells"
Authored by: hayne on Feb 22, '05 06:22:00PM
Whenerver you open a new terminal window in OS X, you are invocating your shell implicitly as an interactive shell. Logout in this circumstance just doesn't make any sense - speaking from a unix standpoint of view.
Actually, each new Terminal window starts a "login shell". You can see this by looking at the parent process of the shell - it is 'login'. This is important to know because it means that, for example, bash does not read the ~/.bashrc file when a new Terminal window is opened, but it does read the ~/.profile file (see 'man bash').

And this is the reason why typing 'logout' in a Terminal window will close that window, while 'exit' merely quits the shell and leaves the window open. If you start a sub-shell by typing 'bash' in a Terminal window, then that sub-shell is a non-login shell and so 'logout' gives you an error message.

In contrast, a new xterm window starts a non-login shell.

[ Reply to This | # ]

new Terminal windows run "login shells"
Authored by: PeteVerdon on Mar 12, '05 04:48:07PM

> 'exit' merely quits the shell and leaves the window open

Not on my machine, it doesn't. I always use exit to close a terminal window, because I didn't log in to it and so that's what feels natural after years of Unix. logout also works, as a convenience, but I don't use it in local windows.

Pete



[ Reply to This | # ]