Linux Shutdown Restart Process Analysis

Source: Internet
Author: User
Tags apm

Linux shutdown and restart process is not important for general desktop applications and Web servers, but in the user's own definition of embedded system kernel has some research significance, by understanding the Linux shutdown restart process, we can modify and customize, and even on this basis to develop new features.

1. Overview

The shutdown and restart under Linux can be triggered by two behaviors, one by user programming and the other by the system's own generated messages. There are two ways in which users interact with the system, one is the system call: Sys_reboot, and the other is the APM or ACPI device file, which can be shut down or restarted by the operation of the system.

#FormatImgID_0 #

2. Reboot via system call Sys_reboot

This system call defines a series of magic_number, first checking whether the Magic_number is correct at the beginning of the call, and only if it is correct to continue running down. Turn to branch at reboot

Case Linux_reboot_cmd_restart:

Start by using Notifier_call_chain to send the restart message to the other part, and then call the Machine_restart function to complete the restart.

The beginning part of the Machine_restart function has an SMP-related code that completes the reboot operation by one CPU when the CPU is mostly completed, and the other CPUs are in a wait state. After the system according to a variable Reboot_thru_bios content to determine the restart mode, by reading Reboot_setup we can be informed that the content of this parameter is specified at the time of system startup, determines whether the use of the BIOS, in fact, the system reset the entrance ( ffff:0000) address of the program to restart. In the case of not rebooting through the BIOS, the system first set the restart flag, and then write to Port 0xFE digital 0x64, the specific principle of this restart I am not clear, it seems to be simulated a reset key press, I hope you and I discuss. In the case of a BIOS reboot, the system also sets the restart mode, then switches to real mode and completes the reboot via a ljmp $0xffff,$0x0.

#FormatImgID_1 #

3. Shutdown via system call Sys_reboot

On the processing branch of the system call, we can see that the Magic_number is checked first, and then the

Case Linux_reboot_cmd_power_off:

In the execution of the process, but also the use of Notifier_call_chain issued a shutdown of the computer power messages, followed by the implementation of the Machine_power_off function. As we can see in the Machine_power_off function, if pm_power_off This function pointer is not NULL, then the system will shut down by calling this function. In the case where APM is already loaded (except for SMP), the Pm_power_off function actually points to the Apm_power_off in Apm.c, where the system passes the values in the APM_INFO structure, switches off to real mode, or uses apm_ The Bios_call_simple function calls the APM interface in protected mode shutdown two methods.

#FormatImgID_2 #

The shutdown process of the 4.APM drive itself

APM completes the APM operation using the IOCTL interface of its registered device, and the processed branch can be seen in the Do_ioctl function of APM.C. There's only suspend and standby code, so we can't use APM to shut down using the IOCTL method.

When the user presses the power switch, if there is an APM module, the shutdown process is handled by APM. The APM driver initiates an APM kernel thread at initialization time: Apm_mainloop, where the Poweroff key message is detected and named Apm_sys_suspend, to distinguish apm-s settings from Apm_user_ Suspend mode. Immediately after entering the Apm_event_handler function, and from the Apm_event_handler function into the check_events function, the processing function corresponding to the case branch. The system also uses the Suspend function to shut down the machine, but for other parameters, suspend finally calls the shutdown process. This article is edited by "Www.zrnkyy.com"

Linux Shutdown Restart Process Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.