The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
finding idle time of a process Krrishv Shell Programming and Scripting 36 01-10-2007 06: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 07: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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
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.
Reply With Quote
Forum Sponsor
  #2  
Old 04-06-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 791
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 ~]$
Reply With Quote
  #3  
Old 04-07-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
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.
Reply With Quote
  #4  
Old 04-07-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
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
Reply With Quote
  #5  
Old 04-07-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
(Never mind, pointed out related thread but moderator closed the other thread so taking away my pointer there.)
Reply With Quote
  #6  
Old 04-07-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
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.
Reply With Quote
  #7  
Old 04-07-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
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 11:11 AM. Reason: Philosophical remarks on "idle"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
idle time, load average, performance, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0