13

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?

EMBLEM
  • 285

1 Answers1

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.

muru
  • 72,889
  • 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 08: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 08: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
  • @SlySven You might be interested in http://askubuntu.com/a/549321/158442. Upstart init just reloaded when hit by SIGTERM. – muru Feb 17 '16 at 13:20
  • I was actually looking at the source code of sysV init within the last week! 8-) - I'm writing a UPS driver for a Raspberry Pi UPS and (being unwilling to allow systemd anywhere near my equipment) was looking at how to use the man-page indicated FIFO method of talking to init - I did try switching from sysv init to upstart on one of my Debian PCs - and hadn't read the small print {not possible, at least not directly like I tried - I had to reboot from a rescue OS on a USB stick, mount and chroot the original system drives and reinstall init - I was not impressed with upstart!} 8-/ – SlySven Feb 19 '16 at 04:09