What constitutes "activity" for the purposes of the Unix "who" command? We're trying to find idle sessions but have disagreements as to the precise meaning of the activity in this context. One person contends that the activity time is only reset by user input--that is, data coming into the session from standard input. Others are saying any CPU activity. An authoritative answer would be useful.
2 Answers
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
jferland pts/2 jferland:S.1 10:35 2.00s 0.18s 0.18s /bin/bash
jferland pts/3 jferland:S.2 10:35 45.00s 0.18s 0.00s sleep 30
jferland pts/1 jferland:S.0 10:35 0.00s 0.21s 0.00s w
S.0: The one I'm checking on, so definitely 0 time there.
S.1: I left a shell open. Two seconds before I pressed a key without pressing enter. So, any input received works even without a line return.
S.2: I ran while true; do echo "foo"; sleep 30; done. I even typed a character in the middle of it. Since the input was blocked (never read), I still appear idle there.
Conclusion
Idle time is reset when a character is read from the terminal input. Blocked input doesn't update idle time even if it does affect the screen display. Applications may update under different rules. For example, I used write which reads input by line, so it only updated my idle time upon pressing enter. The same was true for perl (literally executed as perl with no arguments).
- 20,687
- 2
- 63
- 85
-
+1 - Idle time is based on when the system last handled input from the terminal associated with the session (you could have a bunch of stuff in the buffer like Jeff demonstrated, but you're "idle" until there's some input to handle. If you want to know the last time the terminal saw any activity you can check the access time on the TTY device -- That will update for output as well as input. – voretaq7 Jun 04 '12 at 14:47
Processes run all the time, and it doesnt matter for idle time.
If you do a:
while true; do w; sleep 0.1; done
in one terminal, and open another terminal, you will see that idle time of that other session is reset to zero, only when user inputs something (presses a key). If you run:
while true; do ls; done
in the other terminal the idle time will continue to rise.
So only when the session reads user input, the idle timer is reset.
- 10,722
whocommand? Mine (OS X, FreeBSD) don't know nothin' about activity. Perhaps you meanw? Or perhaps your OS has awhothat behaves differently? Hard to say without knowing what particular Unix-like environment you're working in :) – voretaq7 Jun 04 '12 at 14:42