Say I am writing my own init program running on a Linux kernel.

What happens when my init program exits with return value 0 ?

Additionally is the behaviour different if the return value is non-zero?

What happens when my init program exits with return value 0?

This code, from the find_child_reaper function in kernel/exit.c, is run:

panic("Attempted to kill init! exitcode=0x%08x\n",
       father->signal->group_exit_code ?: father->exit_code);

And consequently this message appears on your console:

Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000
  • Thank you! I misunderstood the message, and was thinking this is the kernel panic you will get if you try to send a kill signal to init, not the action performed if init just returns. Apr 28 '15 at 9:13
  • 2
    @BjarkeFreund-Hansen There is no such thing as "just returns" for a process. When you return from main in a C program, you return to a stub function in the C library that then invokes a system call to end the process, just as if you called exit(). Mar 21 '17 at 22:54
  • 1
    @DepressedDaniel: Thank you, that broadens my understanding. :) Mar 29 '17 at 8:04
  • 1
    Wow! The crap you learn just passing through is amazing. Mar 5 '18 at 18:57
  • 1
    If someone is wondering what the ?: means, look here: stackoverflow.com/a/3319144. In summary: the syntax x ?: y is a nonstandard GCC extension and is equivalent to x ? x : y.
    – jp48
    Aug 6 '19 at 20:13

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.