kill command in Linux can send many different signals to a process. One of them could be STOP which would freeze that process until you send a CONT signal. All that without killing anyone.
If you really want to kill, then use the TERM signal.
Multiple open browsers can share memory, and as others suggested, I wouldn't like my browser to be closed and my research lost.
Wasting CPU when there is nobody doing something... that's different.
Long time ago I created a script that would do that; freeze & unfreeze browsers following the status of the screensaver.
Part of the code came from https://www.jwz.org/xscreensaver/man3.html
I copy the example here:
#!/usr/bin/perl
my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while (<IN>) {
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system "sound-off";
$blanked = 1;
}
} elsif (m/^UNBLANK/) {
system "sound-on";
$blanked = 0;
}
}
You can do the signalling with
system "killall --ignore-case --quiet -s STOP iceweasel chromium firefox firefox-esr";
system "killall --ignore-case --quiet -s CONT iceweasel chromium firefox firefox-esr";
Now you need to glue the pieces, adapt to your specific screensaver and browsers, and test.
Another example could be (again, depending on the screensaver used)
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
while read x; do
case "$x" in
*"boolean true"*) echo SCREEN_LOCKED;;
*"boolean false"*) echo SCREEN_UNLOCKED;;
*) echo OTHER_CASE;;
esac
done
which comes from Run script on screen lock/unlock