3

Can someone tell me how to remove dormant X sessions. This question is similar to Logging out other users from the command line, but more specific to controlling X displays which I find hard to kill.

I used the command "who -u" to get the session of the other screens:

$ who -u

Which gave me:

user1   :0           2014-08-18 12:08   ?          2891 (:0)
user1   pts/26       2014-08-18 16:11 17:18        3984 (:0)
user2   :1           2014-08-18 18:21   ?         25745 (:1)
user1   pts/27       2014-08-18 23:10 00:27        3984 (:0)
user1   pts/32       2014-08-18 23:10 10:42        3984 (:0)
user1   pts/46       2014-08-18 23:14 00:04        3984 (:0)
user1   pts/48       2014-08-19 04:10   .          3984 (:0)

The kill -9 25745 doesn't appear to do anything.

I have a workshop where a number of users will use the computer under their own login. After the workshop is over there are a number of logins that are left open. I would prefer to kill the open sessions rather than try to log into each users' screen.

Again, this question isn't just about logging users' out. I'm hoping to get clarity also for killing/removing stuck processes that are hard to kill.

L. D. James
  • 25,444

2 Answers2

0

I've noticed that the kill command doesn't always work the first time. Also there are times when it'll work, but just have a delayed response.

In the case of killing a login session, it most likely takes time for all the processes to die or be killed. So I wrote a script that checks and follows up with subsequent kills that has always succeeded to log out the desired X session.

#!/bin/bash

results=1   
while [[ $results > 0 ]]
do
    sudo kill -9 25745
    results=$?
    echo -ne "Response:$results..."
    sleep 20
done
L. D. James
  • 25,444
0

To kill all logged in users for :1 use this command:

awk '/\s:1\s/ {system("sudo kill -9 "$6)}' <<< $(who -u)

In your case user2

user2   :1           2014-08-18 18:21   ?         25745 (:1)

Or all sessions for user2 by the username

awk '/^user2\s/ {system("sudo kill -9 "$6)}' <<< $(who -u)
A.B.
  • 92,125