View topic - Killing idle tasks

Killing idle tasks

For the old QNX2 and QNX4 RTOS

Killing idle tasks

Postby twill » Tue Feb 25, 2003 8:04 pm

We are running 4.25 and TCP/IP 5.0 and allow remote access to our computer using inetd. However, we have some users who leave their sessions open for days at a time.

I would like to be able to kill processes that have been idle for some amount of time. Would anyone already have a script file to do this?

I've been working a script myself and have found the "who -o" will give me the idle time I'm looking for, but when I try using sin or ps to get the PID to kill, the times being reported are not actually idle time.

Here is what I've tried if anyone has any suggestions:

who -i | grep -v -e System -e root -e Userid > $TMP

users=`awk '{n=split($6,a,":"); if( n >=3 && a[1] >= 8 ) \
{ print $1 } }' < $TMP`
for u in $users; do
time=`date "+%H:%M%, %m/%d/%y"`
processes=`ps -F"%p %T %c" -u $u | awk '{ n=split($2,a,":"); \
if ( n >= 3 && a[1] >= 8 ) { print $1 } }'`
if [ "$processes" != "" ]
echo "---------------------------------------------------------------" >> $LOG
echo " Killing idle tasks for $u on node $NODE at $time" >> $LOG
echo "---------------------------------------------------------------" >> $LOG
for p in $processes; do
sin -p$p >> $LOG
kill -9 $processes

/usr/local/bin/Mail -s "Idle tasks" admin < $LOG

New Member
Posts: 2
Joined: Thu Dec 05, 2002 6:54 pm

Postby noc » Tue Feb 25, 2003 11:55 pm

not sure about qnx's ksh, but if your users are using "tcsh" as the login shell, you can set the "autologout" shell variable.
set autologout=25
(this will logout the user after 25 minutes)

On my Sun box, the "ksh" has a TMOUT env variable:
TMOUT If set to a value greater than zero, the shell will
terminate if a command is not entered within the
prescribed number of seconds after issuing the PS1
prompt. (Note that the shell can be compiled with a
maximum bound for this value which cannot be
Senior Member
Posts: 1634
Joined: Sat Jul 06, 2002 4:34 am

Return to QNX2 and QNX4

Who is online

Users browsing this forum: No registered users and 3 guests