Gracefull Exit
Posted in 1995
> > > I would also be interested in an application that will cause > > > user's to exit an application gracefully after being > > > inactive for a certain period of time. > > > [...stuff deleted...] > > > > We use a simple shell script which monitors the "idle" time in the > > w command and kills the application part (not the sqlturbo part!) > > of the users process. I don't remember if we do it, but it would > > be trivial to send a clear screen and a "you've been terminated" > > message to the tty to let the user know. > > [...stuff deleted...] > Would you be so kind as to share a copy of the faster, cheaper, smaller > version? Thanx much. > -- > > Dan Madvig e-mail: d-madvig@bethel.edu > Bethel College & Seminary phone: (612) 638-6414 Unfortunately, and often unfairly to the net, my company has a very backwards/anal/silly policy about publishing anything that looks like code. I got in trouble once for that, but not so far for just voicing my opinion or (maybe) solutions that I can offer "off the top of my head". That said, let's see how much I can remember without looking at the copyrighted code... First do a `w -h` to get a list of users and their idle times, and what tty they're on. On DEC Ultrix, this will always present only the front end processes, and never the sqlturbo back ends. Then grep out any users you don't want to ever auto-kill (such as informix, root, yourself). Then read thru the list of processes, parsing each one for the idle time, and if the time is too high, use `ps` to get the pid of the offending process. Then check to see if the username and tty for that process is listed in the tbstat -u as having an X in the 3rd position flag, and see if the address is listed in the tbstat -s as having a latch. We used `cut` and `sed` to find the parts of these commands that we wanted to see (the tty, pid, lock and latch status, etc). Finally, we send a clear to the user's tty, and an echo to the log file saying what we did, and kill -9 the user's tty. You can use a kill -15, and not worry as much about killing a process in a critical section, but there are many processes it won't kill off at all. Run this from cron as root. Actually, we left some of the informix safety, but it has been working without a problem for more than 2 years... This is the way _I'd_ do it if I had to do it again. Thanks to William Zhu (bzhu@ma.copley.com) for the improvement suggestions. Good luck, (but you won't really need it, this is pretty easy) __________________________________________________________________ | Clem Akins Standard Disclaimers Apply | |Reynolds Metals Co, Alloys Plant "Climb High, Cave Deep!" | | Muscle Shoals, Alabama USA cwakins@leia.alloys.rmc.com | |________________________________________________________________|