9

Sometimes, when I have numerous tabs open in Firefox, one of those tabs will start consuming a lot of CPU%, and I want to know which tab is the culprit. Doing this is a very manual process for which I'd like to find automation.

I wish I had an application that could monitor firefox exclusively in a manner that produces concise output of only the firefox-facts I want to know.

I'm looking for a command/application that will list the processes of each tab running in firefox filtered to only include the following info for each tab-process:

  1. Process ID
  2. Webpage Address of Tab
  3. CPU % usage
  4. Memory used

Additionally, I'd like the info sorted by CPU % descending.

Basically, I hoping there exists a program like htop, but that's exclusively dedicated to just the pertinent stuff I want to monitor in Firefox (while leaving out all the details I don't care about).

3 Answers 3

9

You can type about:performance in the address bar of firefox. Then you will get a table where there will be pid of each tab of firefox with Resident Set size and Unique Set Size. And below this there will be some lines explaining the performance of each tab (like performing well) and if a tab is not performing well then it will show there and you can close that tab from there using the Close Tab option.

2
  • 3
    about:performance gets a total redesign with more and better information from FF65.
    – pLumo
    Commented Nov 27, 2018 at 10:07
  • 2
    Suggestion: This answer might want to explain the recent changes made to about:performance before and after Firefox 65. There is no more table with "pid" or "set size".
    – user125388
    Commented Feb 4, 2019 at 7:50
2

You may want to go one step further, and automate the process:

  • Auto-detect processes (which can be running in browser tabs) which are hogging your CPU
  • Terminate them if/once they exceed certain/unreasonable thresholds

Here's a generic/customizable script I wrote, called cpu-hog-killer to address this issue of malicious or otherwise misbehaving scripts in browsers (or elsewhere).

The script defines two basic primitives:

  • process-list: pick processes based on a command+args regex
  • terminate-hogs: kill processes exceeding desired CPU (total-seconds & current %pct) consumption

and uses them to achieve this goal.

Here's the description, as taken from the README.md in the git repo.

cpu-hog-killer

Kill high-CPU hogging processes by command+args regex & CPU consumption.

Buggy (or malicious) 3rd-party javascript code is often taking our browsers and computing resources hostage.

I used to find some processes on my desktop running at 100% CPU all night when I was not even noticing, because of bad javascript.

Involuntary CPU hogging might be caused by an infected ad, badly written code, "drive-by-scripting" leading to someone co-opting your computer to run crypto-mining, or much worse.

It makes you pay for electricity you don't want to, and multiplied by many desktops and browsers left running at night, is also very bad for our planet.

cpu-hog-killer is a simple script which I run from periodically during the night. I make it run from cron every 13 minutes like this:

    # Add this line (or similar) using 'crontab -e'
    */13 0-7 * * *  ~/bin/cpu-hog-killer

It identifies certain CPU hogging processes, mainly inside Chrome or Firefox, and kills them instantly upon detection. Note that it doesn't kill processes taking CPU indiscriminately, nor it kills the main browser process. It only kills those processes that you explicitly say you want terminated based on configured regex + CPU consumption parameters.

In the morning when I'm back, the worst case scenario is that I go to a browser tab and it says (e.g. for Firefox):

    "Gah. Your tab just crashed."

I take notice of which site was misbehaving (based on its title) and the browser allows me (presenting a big button) to:

    [Restore This Tab]

if I want to, so nothing is actually lost.

You can add more rules to the script to cover more apps that may be hogging your CPU when you don't want them to. Just look at the 'main' section (last few lines of the script) and add more rules as needed. Each rule looks like this:

    # [max_cpu_secs] [max_cpu_pct] are optional parameters to terminate-hogs
    # if not specified, default values will be used
    process-list '<some pattern>' | terminate-hogs [max_cpu_secs] [max_cpu_pct]

For example, the Firefox rule which only kills one process tab is:

    process-list '[/]firefox -contentproc -childID.*tab$' | terminate-hogs

And for Chrome/Chromium it is:

    process-list '[/]chrom(e|ium) --type=(renderer|utility)' | terminate-hogs
1

UPDATE The seems to be working for the usage in bash:

watch -n 1 "ps aux | grep firefox"

watch -n 0.1 "ps aux | grep firefox"

watch -n 1 "ps aux | grep firefox && free -m"

Press F5 in Tab and watch

When i kill the tab now with the right tab, i get the message tab is crashed now

In Firefox, about:performance is right.

But check also this in bash if i close or open and load a page tab:

$ pidof firefox

$ pidof firefox-esr

$ pgrep firefox get the main/parentid of one or "n" profiles

$ pgrep firefox-esr get the main/parentid of one or "n" profiles

Get parentid and childid

$ ps aux | grep firefox

$ ps aux | grep firefox | grep tab

You see the parentBuildID and something of the child/tab

It looks like that you can't kill the child/tab only the parentBuildID.

ps -ef | grep firefox | wc -l

1
  • Try: ps aux | grep firefox | awk '{print $2, $11, $3}' | sort -k3rn. Still missing the URL though. Commented Dec 27, 2022 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .