Score:7

How to kill firefox from command line

ng flag

How to kill firefox from the command line?

I have tried:

pkill firefox # the command was known to work previously
pkill -9 firefox
kill -9 firefox # descibed in https://unix.stackexchange.com/questions/8916/when-should-i-not-kill-9-a-process
bash: kill: firefox: arguments must be process or job IDs
killall firefox #described in https://appuals.com/restart-firefox-command-line/

All in vain.

enter image description here

The output of

ps aux | grep -i firefox | grep -v grep

is

v           2419  1.7  7.7 4026824 458876 ?      Sl   12:56   0:51 /usr/lib/firefox/firefox -new-window
v           2483  0.0  0.6 190540 38684 ?        Sl   12:56   0:00 /usr/lib/firefox/firefox -contentproc -parentBuildID 20210927210923 -prefsLen 1 -prefMapSize 246254 -appdir /usr/lib/firefox/browser 2419 true socket
v           2515  0.0  2.0 2407620 119704 ?      Sl   12:56   0:01 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 102 -prefMapSize 246254 -jsInit 286204 -parentBuildID 20210927210923 -appdir /usr/lib/firefox/browser 2419 true tab
v           2553  0.5  2.6 2572708 156816 ?      Sl   12:56   0:16 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 268 -prefMapSize 246254 -jsInit 286204 -parentBuildID 20210927210923 -appdir /usr/lib/firefox/browser 2419 true tab
v           2581  0.0  1.6 2406928 99740 ?       Sl   12:56   0:01 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 4889 -prefMapSize 246254 -jsInit 286204 -parentBuildID 20210927210923 -appdir /usr/lib/firefox/browser 2419 true tab
v           2612  0.3  3.7 2648096 225204 ?      Sl   12:56   0:09 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 5588 -prefMapSize 246254 -jsInit 286204 -parentBuildID 20210927210923 -appdir /usr/lib/firefox/browser 2419 true tab
v           2866  0.0  1.2 2373260 72628 ?       Sl   12:58   0:00 /usr/lib/firefox/firefox -contentproc -childID 5 -isForBrowser -prefsLen 5701 -prefMapSize 246254 -jsInit 286204 -parentBuildID 20210927210923 -appdir /usr/lib/firefox/browser 2419 true tab
v           2998  0.0  0.6 194220 39176 ?        Sl   13:12   0:00 /usr/lib/firefox/firefox -contentproc -parentBuildID 20210927210923 -prefsLen 5926 -prefMapSize 246254 -appdir /usr/lib/firefox/browser 2419 true rdd
David avatar
cn flag
Why the picture you already said that it adds nothing. Why do you want to kill firefox?
Viesturs avatar
ng flag
@David, to start a fresh session of firefox
24601 avatar
in flag
have you considered the efforts in [this](https://unix.stackexchange.com/questions/8916/when-should-i-not-kill-9-a-process) resource? There are some further methodologies [here](https://appuals.com/restart-firefox-command-line/)
FelixJN avatar
im flag
`no process found` - maybe it is not `firefox` but e.g. `firefox-esr`. What is the output of `ps aux | grep -i firefox | grep -v grep`?
Viesturs avatar
ng flag
@FelixJN, I pasted the command output in the question
Jon avatar
us flag
Jon
When I go in the terminal and do the keys control c then it exit from Firefox. But that's in Linux mint.
Score:8
ug flag

tl;dr: pkill -f firefox does the trick.

I found this in the pkill/pgrep manpages:

The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. Use the -f option to match against the complete command line, /proc/pid/cmdline.

With /usr/lib/firefox/firefox having PID 691953 when testing locally on my machine, I found the following in /proc/691953/stat:

691953 (GeckoMain) .... # truncated by me

Doing a pkill GeckoMain killed firefox as promised. killall GeckoMain works too.

The simplest workaround is probably to supply the -f flag to pkill to match against /proc/<pid>/cmdline, which in my case contained /usr/lib/firefox/firefox.

Viesturs avatar
ng flag
`pkill -f firefox` works. Maybe there is no need for such a complicated answer.
frippe avatar
ug flag
Well, I think it's interesting to know why a plain `pkill` works for most process names, but not for firefox. But I hear you, so will add a tl;dr
Score:2
nl flag

kill only works with the process ID

  1. Open a terminal and make it full screen
  2. Type ps -ef | grep firefox to display ALL the firefox processes
  3. The Process ID # is the second column
  4. You are probably after the one at the top with argument -new-window (it's not always at the top)
  5. If you are unsure type top and confirm the process ID of the firefox process that you want to kill
  6. Then type kill -9 1234 where 1234 = your process ID.

Similar answer here

Viesturs avatar
ng flag
`kill -9 6110` works, where is `6110` given by `ps -ef | grep firefox`, corresponding to the line `v 6110 1569 28 17:57 ? 00:00:08 /usr/lib/firefox/firefox -new-window`
Score:1
tr flag

I know you need a simple command. Better you do an alias for:

pgrep firefox | xargs kill

Eg.: a permanent command. Edit your ./bashrc file.

$ vim ~/.bashrc

Find a place in the file, where you want to keep the aliases. For example, you can add them in the end of the file. For organizations purposes you can leave a comment before your aliases something like this:

alias foxkiller="pgrep firefox | xargs kill 2>/dev/null"

If you want to use the newly defined alias foxkiller in the current session, issue the following command:

$ source ~/.bashrc

So you'll have a foxkiller command to kill Firefox.

mickmackusa avatar
ve flag
Thank you for contributing. After 5 years of membership, you have yet to take the [tour]; please do.
Score:0
es flag

I have written a small C app, which does the trick

kkill firefox

will kill all running instances

needless to say, it can be used for any process name

kkiller is a daemon, will watch for requested names and kill them if they become active processes

You can find it here:

kkill, kkiller on GitHub

es flag
How kind of you not to downgrade. Please compile and see that kkill is simpler than pkill in respect of killing multiple instances with the same or other name, or if you require a 'pkill' daemon. Why is compiling a simple C app with a build script ready complicated ?
Someone avatar
my flag
Bye.............!
es flag
Suit yourself.. @Someone. I upvoted your comment, as I don't suffer when in sight of someone better :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.