You are not logged in.

#1 2019-03-30 20:52:55

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

How to shut down a difficult application from the command line

A lot of people know that if you want to shut down an application from a command line, one way of doing it is

killall application name

Killall is quick and also easy to remember, but it sometimes doesn't work. What to do then?

Well, there's a very useful utility called pgrep which returns the process identifier number (PID) of any process currently running whose name corresponds to the one you specify.

For example, if firefox is running, this command will find its PID;

 pgrep -fl firefox

You don't even have to type in the application's full name, as it will find all applications with names containing the string you type in and list their PID numbers. So;

 pgrep -fl fire

will work just as well.

Then, you can just type in

kill PID

to shut down any process which appears in your list and that you no longer want to have running.

I run it from root but a quick test showed that it will also run from a user account.

Last edited by Colonel Panic (2019-03-30 21:56:01)

Offline

#2 2019-03-31 01:57:23

bigbenaugust
Member
From: unc.edu / the 919 / KIGX
Registered: 2017-05-20
Posts: 112

Re: How to shut down a difficult application from the command line

You could also use

pkill

instead of

pgrep

and

kill

Another favorite of mine is

xkill

which gives you the little skull-and-crossbones cursor and then click on the misbehaving application.


--Ben
BL / MX / Raspbian... and a whole bunch of RHEL boxes. :)

Offline

#3 2019-03-31 07:06:47

hhh
That's it!
Registered: 2015-09-17
Posts: 7,220
Website

Re: How to shut down a difficult application from the command line

bigbenaugust wrote:

Another favorite of mine is

xkill

which gives you the little skull-and-crossbones cursor and then click on the misbehaving application.

Ooooooo! I didn't know about this command, this is my GoTo for kills now! You misbehave? Red Death for you! Thank you.

Online

#4 2019-03-31 12:13:37

misko_2083
Member
Registered: 2016-05-24
Posts: 158

Re: How to shut down a difficult application from the command line

^ https://youtu.be/8Xjr2hnOHiM?t=99

Left click to shoot, right click for "no more bullets".

Offline

#5 2019-03-31 12:39:28

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

Re: How to shut down a difficult application from the command line

bigbenaugust wrote:

You could also use

pkill

instead of

pgrep

and

kill

Another favorite of mine is

xkill

which gives you the little skull-and-crossbones cursor and then click on the misbehaving application.

Thanks! pkill's a good one too; it also doesn't need the full name of the program in order to work and is quicker and easier to remember than my suggestion. Pgrep gives you the full listing of running processes with the string in the name though, so it gives you a bit more control; you've got time to look at the process you want to kill before actually doing it.

I like xkill as well and have it on a hotkey (Alt-F4).

Last edited by Colonel Panic (2019-03-31 13:15:42)

Offline

#6 2019-04-01 00:43:41

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 5,143
Website

Re: How to shut down a difficult application from the command line

BunsenLabs comes with xkill bound to W+Escape out of the box. cool

Dig in, there are still probably some undiscovered Easter eggs...


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#7 2019-04-01 12:46:54

Pirx
Member
Registered: 2018-08-27
Posts: 15

Re: How to shut down a difficult application from the command line

You can also install lxtask. It displays all running processes and lets you kill any application with right click menu. Unlike xkill it  can deal with programs that don't have graphical interfaces open.

Offline

#8 2019-04-01 15:07:40

damo
....moderator....
Registered: 2015-08-20
Posts: 4,827

Re: How to shut down a difficult application from the command line

Pirx wrote:

You can also install lxtask. It displays all running processes and lets you kill any application with right click menu. Unlike xkill it  can deal with programs that don't have graphical interfaces open.

Or use htop, which BL already supplies.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#9 2019-04-01 17:07:49

Pirx
Member
Registered: 2018-08-27
Posts: 15

Re: How to shut down a difficult application from the command line

damo wrote:

Or use htop, which BL already supplies.

And which should have been suggested at the first place. wink Before Bunsenlabs, I was using LXDE for years, so I probably stick with lxtask, but if I didn't htop would be an obvious choice.

Offline

#10 2019-04-01 22:31:11

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

Re: How to shut down a difficult application from the command line

Pirx wrote:
damo wrote:

Or use htop, which BL already supplies.

And which should have been suggested at the first place. wink Before Bunsenlabs, I was using LXDE for years, so I probably stick with lxtask, but if I didn't htop would be an obvious choice.

Thanks for the advice, but I've found htop difficult to use if I've got a lot of processes going on at the same time, because in my experience they then move up and down quite quickly and it's difficult to track any one of them. Pgrep just gives you a static list of processes, all containing the string you supply, and you can then decide what to do in your own time.

I'll give lxtask a look too.

Last edited by Colonel Panic (2019-04-01 22:31:35)

Offline

#11 2019-04-01 22:34:44

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

Re: How to shut down a difficult application from the command line

johnraff wrote:

BunsenLabs comes with xkill bound to W+Escape out of the box. cool

Dig in, there are still probably some undiscovered Easter eggs...

Thanks. I'm more used to Fluxbox than Openbox and I have Alt-F4 as a binding in that, so it's easier for me to remember if I keep the same binding for xkill in both WMs (no reason why I can't use W+Escape as well though).

Last edited by Colonel Panic (2019-04-01 22:41:14)

Offline

#12 2019-04-01 22:49:52

damo
....moderator....
Registered: 2015-08-20
Posts: 4,827

Re: How to shut down a difficult application from the command line

Colonel Panic wrote:
damo wrote:

Or use htop, which BL already supplies.

...

Thanks for the advice, but I've found htop difficult to use if I've got a lot of processes going on at the same time, because in my experience they then move up and down quite quickly and it's difficult to track any one of them. Pgrep just gives you a static list of processes, all containing the string you supply, and you can then decide what to do in your own time.

I'll give lxtask a look too.

The Fn keys can be used to achieve that. A potential problem with xkill is that it can kill a frozen X window, but not necessarily the processes that spawned it.

FWIW I tend to use xkill, but keep an eye on the cpu and mem activity in a conky to see if something persists.

Last edited by damo (2019-04-01 22:51:35)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#13 2019-04-03 21:41:59

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

Re: How to shut down a difficult application from the command line

damo wrote:
Colonel Panic wrote:
damo wrote:

Or use htop, which BL already supplies.

...

Thanks for the advice, but I've found htop difficult to use if I've got a lot of processes going on at the same time, because in my experience they then move up and down quite quickly and it's difficult to track any one of them. Pgrep just gives you a static list of processes, all containing the string you supply, and you can then decide what to do in your own time.

I'll give lxtask a look too.

The Fn keys can be used to achieve that. A potential problem with xkill is that it can kill a frozen X window, but not necessarily the processes that spawned it.

FWIW I tend to use xkill, but keep an eye on the cpu and mem activity in a conky to see if something persists.

Thanks, a good tip there damo. I sometimes use ratpoison and it would be good to have one of its workspaces devoted to htop (I can then switch to and from it as and when I need to).

Offline

#14 2019-04-08 05:56:23

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

Re: How to shut down a difficult application from the command line

I find I'm using pkill a lot now because it's just quicker and easier to type "pkill <string>" than to list all the processes containing a certain string and then kill them.

One occasion when I think my method is better though is when two or more running processes have similar names and you don't want to kill the wrong one.

Last edited by Colonel Panic (2019-04-08 05:56:58)

Offline

#15 2019-04-08 13:04:28

bigbenaugust
Member
From: unc.edu / the 919 / KIGX
Registered: 2017-05-20
Posts: 112

Re: How to shut down a difficult application from the command line

Sometimes when using pgrep or pkill, it gets frustrating because they don't use the full command line by default. That is what the -f flag is for. I use that one in a few scripts to reliably get PIDs.


--Ben
BL / MX / Raspbian... and a whole bunch of RHEL boxes. :)

Offline

#16 2019-04-10 07:05:23

ohnonot
...again
Registered: 2015-09-29
Posts: 3,568
Website

Re: How to shut down a difficult application from the command line

careful with pkill and wildcards/regex!
it is possible to kill your whole desktop with a malformed pkill command (an empty regex for example).
it will faithfully kill all processes that contain "" (i.e. an empty string) in their name!

Offline

#17 2019-04-16 08:48:24

Colonel Panic
Member
Registered: 2018-11-13
Posts: 24

Re: How to shut down a difficult application from the command line

Thanks for the warning. I don't really use wildcards / regex with pkill though; if I want to shut down vivaldi, for example, I'll type "pkill vival" at the command prompt.

Last edited by Colonel Panic (2019-04-16 09:16:09)

Offline

Board footer

Powered by FluxBB