I am running xubuntu on a shared low-ressources computer. I would like to run a script that kills the browser (firefox and chromium) whenever the user locks the screen, so that other users can use the ressources.

I believe this is not very hard to do, but I have zero experience in that. Can somebody help, I guess a short script should do it ?

Thank you all.

3 Answers 3


Since you use a low-resource system, I'm going to guess that the default screenlocker is xlock without any screensaver turned on. In that case, you'll have to edit the command for screen locking from "xlock" to "xlock && pkill firefox" or "xlock && pkill chromium". I don't know more on this, but basically if you add " && " after a command, you can then put another one that will be executed only when the first one is done (e.g. when xlock exits from unlocking the screen).

  • Thanks, this actually is directing me in the right direction I think. The screen lock is lightlocker, I am trying to see how to do that. Might have to change the screenlocker ?
    – redfiloux
    Commented Apr 7, 2015 at 17:16
  • What's the point in killing the browser when the user unlocks the screen? They are going to be starting the browser right away and just use extra resources to restore their session. So what you have achieved is using additional resources and annoyed the users enough to ensure that they will immediately look for ways to bypass the killing.
    – kasperd
    Commented Apr 7, 2015 at 22:12
  • @kasperd I'm not sure what's going in your mind. 1) it's when the screen is locked, not unlocked. 2) it's in our shared office to free resources when we forget to kill the browser, because if 2-3 browsers are on at the same time on different sessions it starts lagging pretty bad. 3) thanks but no thanks for obvious comments.
    – redfiloux
    Commented Apr 7, 2015 at 22:42
  • @redfiloux The suggested command kills the browser after the screen is unlocked, not before. Killing applications is bad for productivity. You don't know how much work time is lost due to unsaved work and time to restore the session. With a browser there is no such thing as saving your work frequently. (I have yet to see a browser which can reliably save and restore full state of all open pages). Moreover you can just freeze the browser instead of killing it.
    – kasperd
    Commented Apr 7, 2015 at 23:08
  • @kasperd Thanks. I'd be interested in what freezing the browser is actually! For background : we are math PhD students and it's the computer in the office. We need it to google some terms from time to time and stuff like that. But it's unusable if 2 or 3 browsers are open (cuz it's a piece of crap, the university is pretty poor!), so that's the only solution I though of. I'm sure there are better ones though, I might look at freezing, thanks.
    – redfiloux
    Commented Apr 7, 2015 at 23:16

Write a screen saver.

This is not as crazy as it sounds. Xlock uses screensavers to draw on the screen that are not part of the screen locker so you can write a simple shell script which kills the browser then execs another screensaver to draw on the screen, and set xlock to use that script as the screensaver. I could probably get it down to about five lines.

  • That's a cool idea. I have to spend some time learning the syntax for writing a script though. I'll probably do that when I have a few hours or so, maybe I'll try tonight
    – redfiloux
    Commented Apr 7, 2015 at 21:33

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:


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;;  

which comes from Run script on screen lock/unlock

You must log in to answer this question.

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