At the kernel, the file involved are kernel/sys.c (just a few functions):<div><br></div><div><div>/**</div><div> *      kernel_halt - halt the system</div><div> *</div><div> *      Shutdown everything and perform a clean system halt.</div>
<div> */</div><div>void kernel_halt(void)</div><div>{</div><div>        kernel_shutdown_prepare(SYSTEM_HALT);</div><div>        syscore_shutdown();</div><div>        printk(KERN_EMERG &quot;System halted.\n&quot;);</div><div>
        kmsg_dump(KMSG_DUMP_HALT);</div><div>        machine_halt();</div><div>}</div><div><br></div><div>EXPORT_SYMBOL_GPL(kernel_halt);</div><div><br></div><div>/**</div><div> *      kernel_power_off - power_off the system</div>
<div> *</div><div> *      Shutdown everything and perform a clean system power_off.</div><div> */</div><div>void kernel_power_off(void)</div><div>{</div><div>        kernel_shutdown_prepare(SYSTEM_POWER_OFF);</div><div>        if (pm_power_off_prepare)</div>
<div>                pm_power_off_prepare();</div><div>        disable_nonboot_cpus();</div><div>        syscore_shutdown();</div><div>        printk(KERN_EMERG &quot;Power down.\n&quot;);</div><div>        kmsg_dump(KMSG_DUMP_POWEROFF);</div>
<div>        machine_power_off();</div><div>}</div><div>EXPORT_SYMBOL_GPL(kernel_power_off);</div><div><br></div><div>since it is exported, the symbol can be called from many different places in the kernel, and thus many different ways of shutting down or hibernation are possible.</div>
<br><div class="gmail_quote">On Tue, May 15, 2012 at 1:09 PM, Peter Teoh <span dir="ltr">&lt;<a href="mailto:htmldeveloper@gmail.com" target="_blank">htmldeveloper@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
i think your question is distro-specific, or at least it differs<br>
between sysvinit and systemd - which is the two main technique of<br>
starting up.<br>
<br>
For Fedora Core 17 beta (my system), it is running systemd:<br>
<br>
<a href="http://lwn.net/Articles/458789/" target="_blank">http://lwn.net/Articles/458789/</a><br>
<br>
and here it shows all the good points about systemd:<br>
<br>
<a href="http://0pointer.de/blog/projects/why.html" target="_blank">http://0pointer.de/blog/projects/why.html</a><br>
<br>
(noting the shutdown features if u are focusing on the shutdown part).<br>
<br>
more info:<br>
<br>
<a href="https://fedoraproject.org/wiki/Systemd" target="_blank">https://fedoraproject.org/wiki/Systemd</a><br>
<br>
[PDF]<br>
<br>
Beyond Init: systemd - LinuxKongress 2010<br>
<br>
<a href="http://www.linux-kongress.org/2010/slides/systemd-poettering.pdf" target="_blank">www.linux-kongress.org/2010/slides/systemd-poettering.pdf</a><br>
<br>
But as mentioned in document above, /dev/initctl is still supported,<br>
which is the traditional means of shutting down.<br>
<br>
In Ubuntu (which uses sysvinit, and shutting down is via<br>
/dev/initctl), u can get the source code for poweroff via:<br>
<br>
&quot;apt-get source upstart&quot;<br>
<br>
and then start navigating through the source code.<br>
<br>
Within util/shutdown.c you can see following:<br>
<br>
* struct request:<br>
 *<br>
 * This is the structure passed across /dev/initctl.<br>
 **/<br>
struct request {<br>
        int  magic;<br>
        int  cmd;<br>
        int  runlevel;<br>
        int  sleeptime;<br>
        char data[368];<br>
};<br>
<br>
/**<br>
 * sysvinit_shutdown:<br>
 *<br>
 * Attempt to shutdown a running sysvinit /sbin/init using its /dev/initctl<br>
 * socket.<br>
 **/<br>
static void<br>
sysvinit_shutdown (void)<br>
{<br>
        struct sigaction act;<br>
        struct request   request;<br>
        int              fd;<br>
<br>
        /* Fill in the magic values */<br>
        memset (&amp;request, 0, sizeof (request));<br>
        request.magic = 0x03091969;<br>
        request.sleeptime = 5;<br>
        request.cmd = 1;<br>
<br>
        /* Select a runlevel based on the event name */<br>
<br>
<br>
There goes all the magic....or some part of it....<br>
<div class="im"><br>
On Mon, May 14, 2012 at 7:31 PM, Asutosh Das &lt;<a href="mailto:das.asutosh@gmail.com">das.asutosh@gmail.com</a>&gt; wrote:<br>
&gt;<br>
</div><div><div class="h5">&gt; Hi List<br>
&gt; I have a query about the linux shutdown or reboot process.<br>
&gt;<br>
&gt; Please can you let me know if the below sequence is correct:<br>
&gt;<br>
&gt; When reboot command is given on the shell:<br>
&gt;<br>
&gt; 1. all user-space process is frozen (by sending some signal ?? )<br>
&gt; 2. all file-systems are remounted as read-only - (sysrq handler does this ?? )<br>
&gt; 3. all drivers, whose shutdown handlers have been defined, are called<br>
&gt; in the reverse order in which these drivers were initialized.<br>
&gt;<br>
&gt; I am not sure what happens after this.<br>
&gt;<br>
&gt; TIA.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Thanks &amp; Regards<br>
&gt; ~/asd<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br>
<br>
<br>
<br>
</div></div>--<br>
Regards,<br>
Peter Teoh<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Regards,<br>Peter Teoh<br>
</div>