User Idle Time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User Idle Time
# 1  
Old 04-06-2008
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.
# 2  
Old 04-07-2008
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 ~]$

# 3  
Old 04-07-2008
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.
# 4  
Old 04-07-2008
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

# 5  
Old 04-07-2008
(Never mind, pointed out related thread but moderator closed the other thread so taking away my pointer there.)
# 6  
Old 04-07-2008
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.
# 7  
Old 04-07-2008
I did this in one window:

Code:
while true; do ls -l /dev/pts/1; done

Then I started typing in another window, which is connected to /dev/pts/1. The time stamp changed immediately, although then -- the granularity being only one minute in the ls -l output -- seemed stuck. Tried again after the minute changed, and again, it updated basically immediately.

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 03:11 PM.. Reason: Philosophical remarks on "idle"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to get average idle time using mpstat

I want to get average idle time of the server using mpstat. The problem I am having is %idle is not in same columns in all the versions of linux. example 1: example 2: I tried below command as generalized solution but as Average as one less column output is not proper. I am... (1 Reply)
Discussion started by: kumarjohn
1 Replies

2. Shell Programming and Scripting

User idle time and kill

Hello.. I have many sleepy users on my Solaris box and need to kill them if they are idle for more than 45 minutes for example...I know who -u gives and the idle time but unable to make a awk line to get the condition perfect. Please help...:wall: (9 Replies)
Discussion started by: wimaxpole
9 Replies

3. Shell Programming and Scripting

Write a scripts to kill idle user for 60 min. & email user list to admin in text file

Folks, I have written one script for following condition by referring some of online post in this forum. Please correct it if I'm missing something in it. (OS: AIX 5.3) List the idle user. (I used whoidle command to list first 15 user and get username, idle time, pid and login time).... (4 Replies)
Discussion started by: sumit30
4 Replies

4. Red Hat

Mouse freezing after idle time

Hi All, I am having a problem where my mouse (USB) is freezing after some idle time, and I am having to reboot everytime that happens. I looked in the file /etc/X11/xorg.config to see if there is an entry for mouse and I could not find it. Instead I found the following entry: Section... (8 Replies)
Discussion started by: jxh461
8 Replies

5. UNIX for Advanced & Expert Users

idle time again

I need to find the idle time on a machine in the manner: How long time ago somebody did the last action with mouse or keyboard? Unfortunately "w" doesn't do this. It produced the following output on a machine a user was actually working on with an application: 15# w 15:55:28 up 15 days, ... (1 Reply)
Discussion started by: elbrand
1 Replies

6. HP-UX

how to fetch idle time

HP-UX B.11.23 ia64 Hi everyone, First of all I am new member to this forum. Thankyou all for this forum, it helped me many times. Coming to my question,I am writing a C program to find the log info of the users who are currently logged in(precisely what who -u do). I am able to get... (0 Replies)
Discussion started by: bhiku matre
0 Replies

7. UNIX for Advanced & Expert Users

To find idle time of a user

Hi All I need to find the idle time of a user... but my OS seems to be not supporting finger $ finger -sh: finger: command not found I need to find the idle time and perform some other operations... So is there any other way i can find the idle time of a user... $ uname -a... (2 Replies)
Discussion started by: Whiteboard
2 Replies

8. HP-UX

vmstat displays cpu idle time at 100%

Since yesterday the vmstat command is displaying the cpu idle time at 100%At each time interval. It never changes. Not sure what it means other than it Quit calculating that stat. And I'm curious why. Using sar I can display a correctCpu idle percent, but vmstat does not. Any ideas why or... (2 Replies)
Discussion started by: tfrye
2 Replies

9. Shell Programming and Scripting

finding idle time of a process

Matez, I have a list of process id's in a text file. I want to know how to find the idle time of a process which are more than 300secs and kill them accordingly. Could you please help me to get these details. I want to write a shell script with this. Thanks..Krish :) (36 Replies)
Discussion started by: Krrishv
36 Replies

10. UNIX for Dummies Questions & Answers

Findout Idle Time Setting

Hi Guru's, How do I find and set the login idle time setting in HP-UX 32? Thanks in advance, Mani (1 Reply)
Discussion started by: jvmani
1 Replies
Login or Register to Ask a Question