Restarting GNOME Shell using Terminal, or How to use SIGHUP

Recently I’ve been using my laptop for some heavy processing and as a result of that GNOME Shell started to freeze every now and then.
Normally when something goes wrong I try “alt+f2” and then “r” which is a shortcut to restart the GNOME Shell, but when it freezes you can only use your mouse … and go to other terminals!

I’m talking about TTYs, one of the most wonderful features of Unix based operating systems, IMO. It is simply fascinating that you can use one set of mouse/keyboard/monitor to login with more than one user at the same time.

Back to the GNOME Shell problem. The solution is simple: send a signal to whatever process that is causing the problem. If it’s flash player or a game just kill it with SIGKILL or pause it with SIGSTOP, but as far as I know, many Linux services recognize the SIGHUP (signal code=1), including GNOME Shell. You can use `kill` or `killall` command to send this signal to programs like this:

# kill -s SIGHUP [pid]
# killall -s SIGHUP [process name]

Here is the description of the signal according to the manual page of signal in section 7:

       Signal     Value     Action   Comment
       ──────────────────────────────────────────────────────────────────────
       SIGHUP        1       Term    Hangup detected on controlling terminal
                                     or death of controlling process

Basically this signal is just poking the process and giving the information with no predefined action (whereas SIGKILL kills the program no matter what), so it’s up to the programmer to define a procedure to be executed in case of receiving that signal.

Fortunately for me, GNOME developers have been kind enough to implement such a procedure that just reboots GNOME Shell without closing child processes (which include all graphical programs!), just as “alt+f2″ “r” does.

That’s it, just don’t kill Linux services, poke them with SIGHUP! ;-)

3 Comments

  1. Posted December 22, 2012 at 12:31 PM | Permalink

    > If it’s flash player or a game just kill it with SIGKILL or pause it with SIGSTOP,

    Please try SIGTERM first before doing SIGKILL. You give to the program being terminated at least fighting chance to do something reasonable before dying.

  2. mahrud
    Posted December 22, 2012 at 2:52 PM | Permalink

    Yeah. I always try sigterm first, especially for terminal programs and more “polite” graphical ones; but if flash player or a game or, as I call it, another “non-polite” app is frozen, do you think there is any chance that sigterm is going to help? I don’t think so …

  3. Esteban
    Posted January 21, 2013 at 6:22 AM | Permalink

    Nice article,
    I’ve tried it and it does work.
    Very useful now that Fedora 18 is very buggy :)

    Thanks :)