-   Linux - Newbie (
-   -   login and non-login shell question (

charging-ibis 09-12-2012 07:59 AM

login and non-login shell question
Hello this is just a simple question When you are at a graphical login to log into a Window manager, Is it considered a login shell or a non-login shell?


tronayne 09-12-2012 08:13 AM

It'll be a login shell; i.e., the content of /etc/profile (and anything it includes, such as /etc/login.defs) will be executed as will your .profile, .bashrc, .whatever.

Where you might experience non-login shells is when you open a terminal window (where you just get a $ as a prompt). That behavior can be altered in your window manager preferences or in the preferences for the terminal program -- in Xfce (and probably others) you can check a box to "run command as login shell" (which executes all the above as if you logged in).

Usually, if you open a terminal and execute

ps -f
you'll see something like this

trona    30585 30583  0 09:07 pts/0    00:00:00 -ksh
trona    30604 30585  0 09:10 pts/0    00:00:00 ps -f

where the dash in front of, in my case, ksh (KornShell) indicates that it's a login shell; the dash won't be there otherwise. You're probably using BASH so the dash would be in front of bash.

Hope this helps some.

charging-ibis 09-12-2012 09:00 AM

Yes i found your information helpful. As a matter of fact i am on the chapter regurding shells lol.
So what your saying is that even though it is a GUI login screen the login shell is running in the background correct?


tronayne 09-12-2012 12:13 PM


Originally Posted by charging-ibis (Post 4778506)
So what your saying is that even though it is a GUI login screen the login shell is running in the background correct?

Well, sort of (and this might be a little more complicated than you're interested in but here goes anyway).

Shell programs -- BASH, Bourne, C, Korn (and others) -- are command interpreters; they're the interface between you on a console or terminal emulator (like an X Terminal) and the operating system. They're not running until you log in. You type a command at a shell program prompt and the shell "forks and exec's" that program. You can create shell programs that perform useful work incorporating such concepts as if-else if-else, for, while and other constructs -- a shell program is a programming language like any other.

Logging in is a different concept and not necessarily related to any of the shells. There are three programs, init, getty and login, used for that purpose.

The init program "is the parent of all processes. Its primary role is to create processes from a script stored in the file /etc/inittab. This file usually has entries which cause init to spawn gettys on each line that users can log in. It also controls autonomous processes required by any particular system." (from the manual page).

In /etc/inittab, there is a default run level defined. On my system it is run level 3 which stops at a full-screen console (no GUI). On your system, it will probably be run level 4 (possibly some other run level but not 0, 1, or 6 which are 0 = halt the system and shut off the power, 1 = single user mode, 6 = reboot). The entry in /etc/inittab will look something like this:

# Default runlevel. (Do not set to 0 or 6)

Now, the different run levels cause init to execute different directives (found in /etc/inittab), most notably for our purposes, the directive for run level 4. Run level 4 will attempt to start gdm, kdm or xdm (maybe one or two others). If you're going to fiddle with it, make sure you write down what the run level was before you change it.

The gdm program, I'm pretty sure, is for GNOME (don't have GNOME on my system, don't know), kdm is for KDE and xdm is if you don't have either of those. Only one of those will get started and it will handle the functions of getty and login.

So what does getty do? If you set your default run level to 3 (you can do that, just edit /etc/inittab and log out). Run level 3 takes you to a console, getty opens a port, prints a login prompt and initiates a login process (you enter your user and password). If you type correctly, you get logged in and are prompted to enter commands until you exit (type Ctrl-D or the word exit) which takes you back to the login prompt (yeah, it's the login program).

You can, of course, star X running: simply enter

at a system prompt and, viola! GNOME, KDE, Xfce or whatever starts and will run until you log out and you'll be back to the console (from which you can log out and log in as another user, log in as root or use su - or use sudo) and shut down the system with shutdown or init 0).

You can always edit /etc/inittab and set the default run level back to 4.

Bottom line, nope, it's not a shell, it's a display manager (that might actually invoke a shell for the login and password but probably not).

You may want to look at the manual pages for init, getty, login and gdm, kdm or xdm (xdm is a manual page, gdm and kdm are probably info pages).

Hope this helps some.

All times are GMT -5. The time now is 10:31 AM.