Login shell?
James Logan III
logan at vsedev.VSE.COM
Thu Nov 3 08:55:27 AEST 1988
In article <10791 at ulysses.homer.nj.att.com> ggs at ulysses.homer.nj.att.com (Griff Smith) writes:
>In article <25721 at bu-cs.BU.EDU>, madd at bu-cs.BU.EDU (Jim Frost) writes:
>> In article <314 at uplog.se> thomas at uplog.UUCP (Thomas Hameenaho) writes:
>| |One way of deciding wether or not the current shell is the login shell
>| |is the fact that the name of the login shell is prependended with a '-'.
>| ...
>> That's not really a good indicator. Instead what I'd do is build the
>> process tree (you can use the output from ps or, better, sps if you
>> can't build it from the actual process table). Find the first entry in
>> the tree for the terminal you want. This will work on any unix
>> system, while the naming convention may not.
>| ...
>> jim frost
>> madd at bu-it.bu.edu
>
>Still not quite right. I usually use an AT&T 630 terminal on a 4.3BSD
>system. The login shell for the terminal is not the same as the shell
>for the current window, and each window has a separate pty connected to
>it. The kludge I use also involves reading the output of ps (ugh): I
>scan back through the process tree until I find a parent with a
>different uid. The child of that process is almost always the login
>shell. For my purposes, this also does the right thing for `su'.
>I'd rather have someone support the concept of a session id so we could
>avoid this sillyness.
What is the purpose? If you just want to find out what if the current
shell is indeed the shell spawned by init(1M) (via getty(1M), login(1)),
then just write a simple C program like this:
--------
#include <stdio.h>
main()
{
if (getppid() == getpgrp())
exit(0);
exit(1);
}
-------
Call it something like "is_top" and use it like this in sh(1) or ksh(1):
-------
if is_top; then
echo "Yes, this is the login shell.";
else
echo "No, this is not the login shell.";
fi;
-------
Or just put printf(3C) statements in the C program itself...
Unless you have a program that explicitly resets the process group ID,
it will be the PID of the login shell (which would be the parent PID
when this C program is running).
Another more accurate way to do this is to use getutline(3C) to
get a utmp structure for your current tty (which won't work with
a multiplexed terminal using sxt's...) and check the parent PID
against utmp.ut_pid. Let me know if you need more details.
I hope this is what you're looking for...
-Jim
More information about the Comp.unix.questions
mailing list