Operating System - HP-UX
1833173 Members
2836 Online
110051 Solutions
New Discussion

Two users logged on same TTY according to who

 
SOLVED
Go to solution
Carl Houseman
Super Advisor

Two users logged on same TTY according to who

I don't know what to make of this - bug? Patch?

root: /: who -m -u
chousema pts/0 Oct 11 15:20 . 3869 10.1.5.2:0.0
applmgr pts/0 Oct 11 02:53 . 4306 10.5.2.5

If I 'ps -ef|grep 4306' I get nothing - so why is who telling me about this login that no longer exists?
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Two users logged on same TTY according to who

Hi Carl:

This is not uncommon. This usually occurs when a session is disconnected without a graceful exit. For instance, this can occur if an end-user in a PC-based telnet session closes the telnet without exiting his/her shell.

Regards!

...JRF...
Carl Houseman
Super Advisor

Re: Two users logged on same TTY according to who

Thanks JRF.

Would "not uncommon" be another way of saying "commonly accepted bug" ?

I was parsing 'who -m -R' to find the IP of the client PC, but since it resolves to two different sessions, it's not reliable. Any better way to do that?
OldSchool
Honored Contributor

Re: Two users logged on same TTY according to who

hmm...

perhaps do a "ps -u" on both, the one w/ running process is the guy you want?
James R. Ferguson
Acclaimed Contributor

Re: Two users logged on same TTY according to who

Hi Carl:

I like that: "not uncommon = commonly accepted bug".

Strictly speaking that's not what I meant. This is akin to killing a process with a 'kill -9' and there for not letting any signal handlers that the user has armed to cleanup temporary files, shared memory, etc.

As for ascertaining which of the entries is correct, I'd simply use the latest session. In that example, that would be pid=3869.

Regards!

...JRF...
Carl Houseman
Super Advisor

Re: Two users logged on same TTY according to who

I still consider it a bug when a command reports a PID that no longer exists in the system.

You long-term hard-core folks may be willing to accept and rationalize this, but that doesn't make it any less of a bug! A system should clean up these inconsistencies by itself, and not report them to the user.

As for my overall problem, I guess I'll have to filter the who results based on the PID that exists. Otherwise it's scripting a comparison of date/time which seems like less fun. The other username which is no longer interactively logged on still owns many valid processes on the system.
Bill Hassell
Honored Contributor

Re: Two users logged on same TTY according to who

The utmp file cannot be kept accurate as long as you have users that crash their sessions, turn off their PCs or otherwise do not type exit to close their session. So the bug is that you are allowing untrained users or unreliable connections to attach to your computer.

Here's the problem: utmp only has login and termination records (plus some global records about the kernel) and who is trying to put the beginning and ending records together. Since the records are sometimes incomplete (because of the user) who is just guessing.

Additionally, applications can write to utmp and corrupt the contents. So, who is just a simplistic command to track begin/end records. Note that a 'session' is not as fancy as it sounds. Unix simply takes an incoming connection (telnet, rlogin, ssh, etc) and attaches the login program and if validated, attaches a shell to the tty device file which runs profiles and shows a prompt. A sysadmin can (wrongfully) use kill -9 to get rid of the shell and now you have an orphaned start record.

So to determine the users that are currently logged on, you need to define logins. Some users may have a shell prompt, others may be running a menu program. But start by running the ps command through sort as in:

ps -ef | grep -v ^root | sort

You can do some other filters to narrow down the actual login shells. ps is always correct.


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Two users logged on same TTY according to who

Like it or not, this is an artifact of incomplete data in the utmp file. Who, at best, is a guess because it tries to pair logins with logouts but if there is no graceful logout then there are no records to correctly pair. Experienced UNIX admins NEVER trust who (and never have) and instead use ps to see actual logins. You should read the getlogin man page where it mentions "the reccomended procedure to obtain the user name" because it deals with an equivalent problem also based upon the unreliability of utmp. This has been the reccomended approach for decades. The OS has no way to gracefully handle a logout if you simply yank the power cord of your PC formerly connected to the UNIX box.

You can use fwtmp to read out your utmp file as text, clean it up, and read it back in as binary but I consider this a waste of time.


If it ain't broke, I can fix that.
Carl Houseman
Super Advisor

Re: Two users logged on same TTY according to who

Caution:

It's a bug that I allowed an unreliable connection? Or an inexperienced user? No points for that!

News flash: The world is unreliable. Users are inexperienced. The computer should be able to deal with it. There's no excuse for reporting false information (JMHO).

Recommmended approach for decades? After all that time, nobody has bothered to fix or rewrite who? What is the recommended method for finding the IP address of the connected device, if not to deal with who?

It's true (and obvious I'm sure) that I'm not an experienced Unix admin and this thread is part of my gaining experience. But I have admin'd various non-Unix OS's over 25 years and have not previously had to deal with a system provided utility that reported false information, where such false reporting was considered acceptable, or even tolerable.

I have my workaround, using ps to filter out bogus PIDs reported by who, but I don't have to like it!