3

In versions prior to 58, a killall chromium-browse[r] was sufficient to kill all tabs while leaving the browser chrome intact. How can this behavior be replicated for the new version of the browser?

The best I've managed is the following which will also take out extensions when doing its thing:

pgrep -f 'chromium-browser --type=renderer' | while read pid; do kill $pid; done

Edit for context: I have the amount of memory that chromium may use restricted by cgroups. When that amount is exceeded, chromium hangs swapping memory from and to disk. Chromium does not respond to user input when in this state, so browser-based tab control is not an option.

Edit for clarity: Killing a tab does not imply closing it. What I want is for the tab itself to remain, but the rendering process to die. This is usually indicated by displaying a "Something went wrong" message instead of normal tab content.

3
  • What's wrong with Ctrl + F4? instead May 7, 2017 at 3:39
  • Right click on the leftmost tab, close tabs to the right. May 7, 2017 at 6:21
  • Apologies. I was not clear in my original post. I have updated the post with the context that gave rise to my question.
    – Doe
    May 7, 2017 at 10:35

2 Answers 2

1

Okay so after your edits; I played around with the command you gave. You said that it destroys extensions as well so to exclude them you can do grep -v "extension" but then you take as input the whole process command.

Anyways. First select the process name

pgrep -f -a 'chrome'

I'm using chrome, you can put chromium-browser instead. The -a flag here is important.

then do

| grep 'type=renderer'

to get all renderers. Then do

| grep -v "extension"

to exclude the extensions, then we need to do

| egrep -o '^[0-9]{0,}'

to get only the process number (since we had to use the -a flag which gives extra data in the string).

Feed that into your for loop

| while read pid; do kill $pid; done

And it should kill renderers without extensions

So finally, here's the whole thing for you:

pgrep -f -a 'chromium-browser' | grep 'type=renderer' | grep -v "extension" | egrep -o '^[0-9]{0,}' | while read pid; do kill $pid; done

I hope I didn't make mistakes

3
  • This is certainly better than my solution; it even excludes the GPU process from being killed. Here's to chromium not changing how supprocesses are invoked or named.
    – Doe
    May 10, 2017 at 9:28
  • glad it works. you see you can chain more grep and grep -v commands in the middle to include and exclude what you like. do a pgrep -f -a 'chrome' by itself to see how the processes look like as they are. cheers :)
    – steoiatsl
    May 10, 2017 at 11:44
  • Worked perfectly! Since I am using Brave browser, i had to pgrep -f -a 'brave' | .... Thank you! No more draining battery with over 200 tabs open.
    – eduncan911
    Sep 18, 2021 at 3:39
1

Ctrl + Shift + w will kill all tabs in the currently selected chrome window without affecting the browser itself.

4
  • 1
    Apologies. I was not clear in my post. What I want is for the contents of the tab to die, but the tab itself to remain displaying a "something went wrong" message. I have updated my post with the context that gave rise to my question.
    – Doe
    May 7, 2017 at 10:34
  • 1
    did you try chrome's task manager? either <kbd>Shift</kbd> + <kbd>Esc</kbd> or the top right menu > more tools > task manager .. and I think you can also use ubuntu's "system monitor"
    – steoiatsl
    May 7, 2017 at 11:12
  • 2
    did you try chrome's task manager? either Shift + Esc or the top right menu > more tools > task manager .. and I think you can also use ubuntu's "system monitor" @Doe
    – steoiatsl
    May 7, 2017 at 15:59
  • Chromes's task manager would work but is part of the browser, and thus is subject to the same cgroup restrictions; it hangs when the browser hangs. gnome-system-monitor is unfortunately equivalent to the command in my original post but is more involved to use. I'm hoping for a better solution.
    – Doe
    May 8, 2017 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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