Killing idle tasks

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

I would like to be able to automatically 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 and have found the “who -o” will give
me the idle time I’m looking for, but when I try using the sin or ps
commands to get the tasks a users is running, the times being reported
from these commands are not actually idle time.

Here is the script file 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” != “” ]
then
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
done
kill -9 $processes
fi
done

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

Thanks,
Tony

Tony Williams <tony@ctcqnx4.ctg.cummins.com> wrote:

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

Ugh. I was looking for some sort of auto-idle timeout, but couldn’t
see one.

Here is the script file if anyone has any suggestions:

One suggestion – don’t “kill -9” send them a SIGHUP instead,
if they have any edit sessions or such around, this will have
the effect of letting the editor catch the hangup and save
the current work, and it is what would be normal in that
situation.

-David

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” != “” ]
then
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
done
kill -9 $processes
fi
done

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

Thanks,
Tony


QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.