5

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?

3
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. – Bjarke Freund-Hansen Apr 28 '15 at 9:13
  • 1
    @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(). – DepressedDaniel Mar 21 '17 at 22:54
  • 1
    @DepressedDaniel: Thank you, that broadens my understanding. :) – Bjarke Freund-Hansen Mar 29 '17 at 8:04
  • Wow! The crap you learn just passing through is amazing. – Bruno Bronosky Mar 5 '18 at 18:57

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.