Let's say I have the window manager Blackbox running on two different X displays, e.g. :0.0
and :1.0
launched from tty1
and tty2
respectively. From a terminal (emulator), how do I exit (kill) the Blackbox process that uses the current X display? The command killall blackbox
does not fit since it terminates both sessions.

- 1,806
3 Answers
ps e
lists processes with their commandline along with ( initial ? ) environment variables . filter processes matching either a -display :0
commandline or a DISPLAY=:0
environment . i believe this find the wm in question whether started manually or by some session script . then we can simply kill
it .
i hear there are different ps implementations , the above ( bsd ? ) commandline style works on my machine with debian procps-ng . refer to the manual if necessary .
based on the observation that wm is owner of the root window , this arch wiki page has a minisection with an approach of xprop -root _NET_WM_PID
to find the pid , . but this don't work for me , seemingly because it is only voluntary for x windows to provide this property , and my wm happens to not follow that fashion .
regarding other nonworking ideas , xkill can detach clients except the root window , so don't fill our need here .

- 841
-
Thanks for the input, I wasn't familiar with the
e
option. One strange thing about the output fromps e
is that there is no space between the command and the environment variable following it, for instanceblackboxMAIL=/var/mail...
. – August Karlstrom Jan 27 '15 at 16:19 -
@AugustKarlstrom , you are right about "cannot xkill root window" , let me delete that answer and put some small information regarding xwininfo and xprop into this answer . – 把友情留在无盐 Jan 27 '15 at 16:24
If you have identified the tty where you lauched the blackbox from, ps -t tty1
will list the processes launched from that terminal (assuming tty1 is the one from where you launched the openbox you want to kill), then you can identify and kill the one you want.

- 4,015
-
That's correct but in the general case I don't know. In my solution posted here I instead start from the
DISPLAY
variable. – August Karlstrom Jan 27 '15 at 17:55
Here is a solution inspired by soubunmei's answer:
#!/bin/sh
ActiveWindowManagerPID()
{
local windowManager="$1"
local windowManagerPIDs="$(pidof "$windowManager")"
local displayNumber="$(echo $DISPLAY \
| awk 'BEGIN { FS = "[:.]" } { print $2 }')"
ps e -p "$windowManagerPIDs" \
| awk -v n="$displayNumber" \
'$0 ~ " DISPLAY=:" n "[\n .]" { print $1 }'
}
kill "$(ActiveWindowManagerPID blackbox)"

- 1,806
ps ux
to find the process. Thenkill
to kill. – ctrl-alt-delor Jan 26 '15 at 21:50ps
usage seems different than mine . i want environment variables as well as commandline arguments . what flavour of unix system are you working on ? – 把友情留在无盐 Jan 27 '15 at 04:38