![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| finding idle time of a process | Krrishv | Shell Programming and Scripting | 36 | 01-10-2007 05:34 AM |
| Automatic time out of user login | keelba | UNIX for Advanced & Expert Users | 2 | 10-06-2005 06:12 AM |
| Findout Idle Time Setting | jvmani | UNIX for Dummies Questions & Answers | 1 | 12-13-2003 06:47 AM |
| logoff idle user script | michieka | UNIX for Dummies Questions & Answers | 4 | 05-24-2002 06:47 AM |
| Killing idle user processes | annette | UNIX for Dummies Questions & Answers | 3 | 04-17-2002 01:50 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
User Idle Time
Does anyone know how do you determine the user idle time of stdin in order to log the user out for being idle too long. I would like to write a c program to do this but I it is not clear upon how to determine idle time from keyboard input.
|
| Forum Sponsor | ||
|
|
|
|||
|
Check if you have w command available to you. One of the columns in its output lists idle time.
Code:
[yogeshs@localhost ~]$ w 11:46:04 up 2:06, 5 users, load average: 0.16, 0.25, 0.21 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT yogeshs :0 - 09:41 ?xdm? 10:59 0.64s /usr/bin/gnome-session yogeshs pts/1 :0.0 09:49 1:55m 0.06s 41.24s gnome-terminal yogeshs pts/2 :0.0 09:56 1:48m 0.04s 0.04s bash yogeshs pts/3 :0.0 09:59 10:32 0.04s 0.04s bash yogeshs pts/4 :0.0 11:45 0.00s 0.03s 0.00s w [yogeshs@localhost ~]$ |
|
|||
|
I am aware of this command along with the who command, I have looked at the source for these files and they use the time now-last access of tty, I would like to determine idle time by using stdin somehow. Also, Id like to be gangster and write it in C.
|
|
|||
|
At least on my system, the mod time on the tty's device seems to be where this information is coming from. If it works the same on your system, you can use that.
Code:
vnix$ ls -l /dev/pts | fgrep era crw--w---- 1 era tty 136, 0 2008-04-07 15:17 0 crw--w---- 1 era tty 136, 1 2008-04-07 14:22 1 crw--w---- 1 era tty 136, 2 2008-04-07 14:26 2 vnix$ w 15:17:26 up 1:49, 4 users, load average: 1.02, 0.45, 0.21 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT era tty7 :0 13:57 0.00s 3:07m 0.92s x-session-manag era pts/0 :0.0 13:57 0.00s 0.30s 0.01s w era pts/1 :0.0 14:22 55:09m 0.17s 0.10s ssh -L 4444:loc era pts/2 :0.0 14:25 51:26m 0.18s 0.00s tail --follow=n |
|
|||
|
ERA -
To check for idle I: set an alarm, and then pause(); during the pause() : I type on the keyboard and it writes to the terminal, but the last access time to stdin or the specific tty are not reflected by my typing. So I have no way to test my program. Does this make sense? Perhaps I am thinking about this wrong. Sorry for double posting. |
|
|||
|
I did this in one window:
Code:
while true; do ls -l /dev/pts/1; done You pause in a program which is running on the terminal you are watching? You want to catch input even when the tty is not actually responding? If I run sleep 600 and then type in something during that time, the tty time stamp does not update. But that would seem to pretty much match a reasonable definition of "idle", from the system's perspective, although certainly from the user's perspective, if you are typoing (oops) at it, you are not idle. If you pwn the system (I guess you do) then I suppose you could attach a kernel module to the tty driver or something ... sounds like too much work. Last edited by era; 04-07-2008 at 11:11 AM. Reason: Philosophical remarks on "idle" |
|||
| Google UNIX.COM |
| Tags |
| idle time, load average, performance, unix |
| Thread Tools | |
| Display Modes | |
|
|