12

On multiple computers running Ubuntu 14.XX, I ran the command "killall init" as user, and was immediately logged out. I could log back in again without a problem. Why is this? What's going on behind the scenes?

21

On newer Upstart systems, a session init process is started when you login using the GUI. Since Ubuntu uses Upstart, there's an init process for your session. Test it out using pstree -ps $$ in a terminal:

$ pstree -ps $$
init(1)───lightdm(1741)───lightdm(9511)───init(9526)───/usr/bin/termin(9570)─┬─gnome-pty-helpe(9734)                                                                                                                                                                                  
                                                                             └──zsh(7944)

So when you run killall init, you're not killing init PID 1 (because you don't have the privilege), but your session init, which would be PID 9526 in this example.

Since this init is the governing process for your GUI session, killing it kills your session and therefore you are logged out.

  • Does killall always send the signal to the closest relative in the process tree? If I ran the command as root (with sudo for example), would I get the same result, or a kernel panic? – Tim Seguine Jan 28 '15 at 8:04
  • 1
    @TimSeguine As the name says, it is sent to all processes with this name. BTW, some people prefer pkill instead of killall because killall works completely different on other systems such as Solaris... – glglgl Jan 28 '15 at 8:09
  • killall kills all. Hence the name. – orion Jan 28 '15 at 12:10
  • 1
    @TimSeguine It sends to all, but if you're an ordinary user you can't send signals to processes of other users. So it only affects the one in your own process tree. – Barmar Jan 28 '15 at 18:20
  • Running killall init as root does not seem like a good idea - especially on a useful system - I think init causes a kernel panic if it dies because it is not intended to ever reach a return at the end of it's main code loop. – SlySven Feb 13 '16 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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