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.
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 .
- Thanks for the input, I wasn't familiar with the
eoption. One strange thing about the output fromps eis that there is no space between the command and the environment variable following it, for instanceblackboxMAIL=/var/mail....August Karlstrom– August Karlstrom2015-01-27 16:19:08 +00:00Commented Jan 27, 2015 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 .越鸟巢南枝– 越鸟巢南枝2015-01-27 16:24:40 +00:00Commented Jan 27, 2015 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.
- That's correct but in the general case I don't know. In my solution posted here I instead start from the
DISPLAYvariable.August Karlstrom– August Karlstrom2015-01-27 17:55:16 +00:00Commented Jan 27, 2015 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)"
ps uxto find the process. Thenkillto kill.psusage seems different than mine . i want environment variables as well as commandline arguments . what flavour of unix system are you working on ?