1

On Windows, this kills any process with "This is a process title" as the title.

taskkill /FI "WINDOWTITLE eq This is a process title"

I've searched all over without finding a single mention of how to do this on Linux.

How to do it on Linux?

That is: not the binary name/command -- the process/window title.

3
  • Get the PID askubuntu.com/q/137875/158442 and then kill it – muru Oct 1 '20 at 5:22
  • @muru Well, I looked at the linked page and I still couldn't figure it out. I thought everything was insanely cryptic and backwards on Windows, but Linux makes Windows' nonsense almost seem... sane? Am I still on Earth? – Simote L. Oct 1 '20 at 6:06
  • Processes do not have titles, and are not necessarily associated with windows. (This is in fact the case on Windows as well.) – JdeBP Oct 1 '20 at 8:55
1

In X11, there is no single unambiguous "process title". The closest equivalent might be the WM_NAME property ("window name"). However there might be more than one window with the same name.

If using X11, you might try:

xprop -name "This is a window title" _NET_WM_PID

to try and get the PID of the process by window title. But depending on the process itself and/or the window manager you're using, it might or might not work: the text in the window's title bar might or might not have nothing at all to do with the WM_NAME property at the X11 protocol level. (The window manager decides if there even will be a title bar in the first place!)

And it looks like xprop will just return the first one it finds, even if there are several matching windows.

If it seems you're getting the correct PID, you can kill it, for example:

kill $(xprop -name "This is a window title" _NET_WM_PID)

And if you use Wayland, these X11 tools and tricks will most likely not be applicable at all. (If you know more about Wayland, feel free to write your own answer or edit this one!)

2
  • This was my first idea, but executed on something like xfce4-terminal the _NET_WM_PID actually corresponds to the parent process for all currently open terminal windows (all of them will close) – Neticegear Oct 1 '20 at 6:50
  • @BarBar1234 Yes, with modern terminal emulators, one emulator process may handle several windows and/or tabs. If your goal is to kill a single shell session, you'll need to find the actual shell process. It is an old-school TTY-based program which knows nothing about windows and their titles. Alternatively, it might be possible to use D-Bus or similar to tell the terminal emulator to close a particular window/tab, but currently the only D-Bus request supported by xfce4-terminal is "start a new session". – telcoM Oct 1 '20 at 12:21
0

A lot of Linux distros now also have pkill installed. e.g. pkill evolution

2
  • 1
    Also, using pgrep -li SomeCharactersOfTheAppName you can get a list of processes based on their name. – Krackout Oct 1 '20 at 7:47
  • The things that the likes of pkill operate upon are not process titles in the Windows sense (e.g. as seen via the .NET MainWindowTitle property of a Process object) and not what the question is talking about.They are the "COMM" fields in the process table, similar to a Win32 process name (e.g. ProcessName). The question does emphasize that the process name is not what the questioner is looking for. – JdeBP Oct 1 '20 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.