[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: stale/defunt sessions in debian



On Sun, Sep 10, 2000 at 09:47:07AM -0500, William Jensen wrote:
> Is the following a product of how debian sets up the system or is it a kernel
> deal or what...

AFAIK, this is a general Linux problem, probably a general UNIX problem...

> If I telnet to my home box remotely, then just kill the session instead of
> logging out it often leaves that connection up in my ps even though I know
> it's gone.  Who cleans those types of things up?

Um, the system administrator.  =)

>                                                 Is there anything that debian
> or linux in geneal does to clean stale things up?

Depends on the "stale thing."  In this case, I don't think Linux would
automatically kill stale login sessions, unless there was a total time or idle
time limit for that user, or of course the system was restarted or the init
runlevel was changed.  However, it's trivial to fix this problem.

If you have the Debian package 'slay' installed, and the owner of the stale
session is only logged in through that or other stale sessions, issue "slay
staleuser" to kill all that user's processes.  Of course, if that user is
logged in doing real work, then his or her session will be terminated.

A less easy but more direct approach is to kill all processes running on the
tty that holds the stale login session with the SIGTERM signal, so as any
important programs should exit cleanly.  After a few seconds, issue a SIGKILL
signal to the person's login shell.

Here's a step-by-step example.  Say the stale login is owned by 'piranha'.  =)
Issue the 'w' command.  You may see something like:

  9:58pm  up  27 years, 4 users,  load average: 1.14, 1.12, 1.09
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU  WHAT
root     tty1                       4:33pm  2:00m  2.50s  2.50s  -bash 
piranha  ttyp8    omega             9:58pm  5:16m  0.17s  0.05s  -bash 
phed     ttyS0                      7:46pm  1.00m  0.19s  0.19s  lynx
piranha  ttyp2    omega             8:32am  9.00s  0.14s  0.04s  zile

You'll see the first listing for piranha is the most idle, at 5 hours, and
that he's on ttyp8.  This is the login you'll want to kill.  So type
'ps aux | grep '^.\{37\} p8 '' (excluding outermost single-quotes), and you
might see:

piranha   7220  0.0  1.9  1888  1268  p8 S    08:32   0:00 -bash 
piranha  12432  0.7  1.0  1100   656  p8 S    08:38   0:00 /usr/bin/zile /home/p

(Note, in that command, 'p8' is for ttyp8.  Put whatever comes after the
'tty'.  If it's one letter/digit, put a space before it, as in '...\}  1 '.)

So to be nice, give zile a chance to exit cleanly, by issuing 
'kill -TERM 7220 1243'.  You should put every PID number (second column of 'ps
...' output) on the command-line with 'kill -TERM'.  Wait a few seconds, and
now issue 'kill -KILL 7220', since 7220 is the login shell (it starts with a
hyphen).  Now the user should be logged out.

You can perform the above steps as the named user, or root, of course.

-- 
 J.P. Larocque, known online as piranha
 piranha@mindless.com
 Fidonet: prowler@1:346/6 (The Garage, 509-326-4609)
 "If you can't make it good, make it LOOK good." -Bill Gates

PS: Yes, the uptime example from 'w' is a -tad- unrealistic...



Reply to: