Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
It couldn't possibly be CPU activity. Processes run constantly on behalf of the user. –  Dennis Williamson Jun 4 '12 at 14:35
    
which who command? Mine (OS X, FreeBSD) don't know nothin' about activity. Perhaps you mean w? Or perhaps your OS has a who that behaves differently? Hard to say without knowing what particular Unix-like environment you're working in :) –  voretaq7 Jun 4 '12 at 14:42
    
Aix, to be more specific. –  Matt Smith Jun 4 '12 at 18:19
add comment

2 Answers

up vote 4 down vote accepted
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).

share|improve this answer
    
+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 4 '12 at 14:47
    
Thanks for the help... –  Matt Smith Jun 5 '12 at 11:30
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.