Subject: who and idle time

From: Phillip Susi <[email-masked]>
Date: Thu, 15 Dec 2011 21:58:25 -0500

I've long wondered why the idle time reported by who is sometimes wrong, mostly with X terminals, and also I recently noticed, when running emacs or less.  I was shocked to see that the time is found by checking the atime of the tty device.  The reason it is sometimes not updated is because emacs and less open /dev/tty, which is effectively whichever controlling tty they are attached to, except that it is a different inode, and so the read()s update the atime of /dev/tty instead of /dev/ttyXX.  At first I thought that I could fix this, but now it occurs to me that the whole concept is fundamentally flawed because you can have multiple inodes that all point to the same chardev, so which one should get updated?

Shouldn't the kernel tty driver keep track of idle time and let you read it with an ioctl?