Killing idle tasks

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” != “” ]
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

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
exceeded.)