Linux shutdown command

Source: Internet
Author: User
Tags set time time and date

The shutdown command is as follows: 1, halt immediately shut down the Machine 2, Poweroff immediately shut down 3, Shutdown-h now immediately shutdown (root user) 4, shutdown-h 10 10 minutes later 5, init 0 (for root users) if the Shut Down command to set the shutdown, you can use the Shutdown-c command to cancel the restart recommended using the Shutdown command

===============================================

Maybe you're not very familiar with the system because of the financial crisis cost savings, so let's start with the shutdown and learn about this seemingly mysterious system. The power off commands are shutdown, reboot, Halt, Poweroff, Telinit, and Init, respectively. While some commands are a parent-child relationship, at least it can be explained that Linux systems are shut down with some knowledge.

"It Business News Network" in the Linux system, its shutdown command of up to six kinds. Respectively, shutdown, reboot, Halt, Poweroff, Telinit, init and other commands. While some commands are a parent-child relationship, at least it can be explained that Linux systems are shut down with some knowledge. These commands can be used to shut down or reboot the system, but they have different workflows for each command, which can serve a variety of purposes. The author goes on to introduce the characteristics of these shutdown commands and under what circumstances should be used to command.

  One, the relationship between the six shutdown commands.

Of these six commands, there are parent-child relationships between the commands. such as Halt and Poweroff Two is a parent-child relationship. In the halt command, if you add the-p parameter, it will play the same role as Poweroff. If your system administrator wants to know if a shutdown command is a connection to another critical command (that is, if there is a parent-child relationship to another shutdown command), you can query with the command shown.

The first record above indicates that the Poweroff command is a connection to the halt command. That is, the Poweroff command is a subroutine of the halt command. The second record indicates that the halt command is not a connection to another command. That is, the halt shutdown command is the top-level command. Therefore, if the system administrator does not understand the relationship between these shutdown commands, you can use the command above to query. These six shutdown commands are all generated by the package Sysvinit, and the system administrator can download its source code from the Internet to analyze the process of each command. As a system administrator, it is important to understand the similarities and differences of these commands and to choose the appropriate shutdown command for your needs. Rather than blindly use the Poweroff command to shut down the machine.

 Second, halt shutdown command parsing.

Halt shutdown command can be said to be the eldest of the six shutdown commands. With different parameters in this command, you can achieve different purposes. In this shutdown command, there are seven main parameters.

Like the-n parameter, it is primarily used to prevent sync system calls. Linux systems are sometimes more efficient, and the data to be written to the hard disk is written first into filesystem buffer. This buffer is a piece of memory space. If the data to be written to the hard disk is stored in this buffer, and the system suddenly loses power, then the data will be lost. The sync command forces the data stored in buffer to be written to the hard disk. This function is like a cache in a database. You can write the changed data to a cache in memory first. Then wait until a certain time to write it to the hard disk. This approach can improve system performance. However, sometimes the administrator needs to prohibit the system from taking sync instructions. If the system administrator patches the partition with the fsck command, in order to prevent the kernel from overwriting the patched super block with the old version of the Super block, the halt–n is used to shut down the machine when it shuts down. In this case, the patched Super block is not overwritten with the old version of the Super block when the computer is shut down.

If you have the-w parameter in the halt command, it is not a true restart or shutdown. Instead, the event is logged into the wtmp log file. As we all know, when the system logs in, the login login program writes some content to the Utmp file and also adds it to the Wtmp log file. When logging off, the INIT process erases the corresponding records in the Utmp file, with each byte filled with 0. and add a new record to the Wtmp file. Special record entries are added to the Wtmp file when the system restarts, and before and after the system time and date are changed. In other words, the wtmp log file tracks individual logon and logoff events, as well as some other special changes. If the system administrator is not really shutting down and just wants to write a tag to the wtmp log file, this halt–w command can be used to accomplish this requirement. In addition,-D is the inverse argument to-W. If you add this parameter while shutting down, you will not add content to the Wtmp log file when you shut down the computer.

With this command, it is sometimes possible to achieve power-saving functions. In laptop computers, there are usually four power-saving modes. One is the doze mode, when the set time is up, the CPU clock slows down and other devices operate as usual. The second is the standby mode, when the set time is up, the hard drive and the display will stop working, and the other devices operate as usual. The third is the suspend mode, when the set time is up, all devices except the CPU will stop working. Four is HDD Power down mode: When the set time is up, the hard drive stops working and the other devices operate as usual. And under the Linux operating system, he supports the second mode, that is, the standby mode. If the system administrator runs the halt-h command, the hard drive of the high-speed Linux operating system is in standby mode to conserve power.

Another parameter,-p, is the default option for this command. If this parameter is used, the command is identical to the Poweroff command. Other relevant parameters you can refer to the system's help file to understand, there is not much to say.

It is important to note that there are user restrictions when using the halt command. That is, after parsing the command-line arguments, the system invokes the GETEUID system process to determine whether the current user is the root user. If yes, follow up, if it is a normal user, halt exits and prompts the user for an error message.

The Visible halt command is a powerful shutdown command. But in a way it is not a shutdown command. Because it can play a lot of role outside the shutdown. As a system administrator, choose the appropriate parameters according to your needs. Only in this way can the power of this shutdown command be played to the fullest.

 Third, shutdown command analysis.

Because the Linux system is a multi-user system. There may be multiple users logged on this system at the same time. such as remote login via SSH command and so on. Then the system administrator may want to warn all current logged-in users before shutting down the Linux system. Or shut down the system after 10 minutes, and so on. If the system administrator wants to implement this function, it will need to use the shutdown Shutdown command.

The shutdown command can safely shut down or restart the Linux system. This command prompts a warning message to all logged-on users on the system, including remote logins, before the system shuts down. The command also allows the system administrator to specify a time parameter to shut down the system after a specified time. If it can be a precise time (in a few minutes), it can also be a time period starting from now (10 minutes later). With this command system all processes will receive the sigterm signal. This has one advantage. It allows text editing programs such as VI to have time to store files that are in the editing state. Application processes, such as mail and news, can remove data from all buffer pools appropriately, and so on. So this is a very user-friendly shutdown command. After the system administrator runs the shutdown command, the system notifies the INIT process that it is required to change the runlevel to implement specific functions. Run level 0 is used to shut down the system, RunLevel 6 is used to reboot the system, and RunLevel 1 is used to bring the system into the System Administration task State. If the-H or-R parameters are not given, this is the default working state of the shutdown command. After the system executes the command, data synchronization is done automatically. The time spent on this command may take a bit longer. However, if the data synchronization is considered, then the administrator waiting for such a period of time is also worthwhile.

The concept of a runlevel is mentioned here, which is also a big difference between the Linux system and the Windows system. The so-called operational level is a system software environment configuration. Only one set of selected processes is allowed to exist in a particular environment. Init processes that are derived from different run levels. Init can be booted to 8 different runlevel levels, including 0-6 RunLevel and S or S run level. The runlevel can be converted by the superuser through the Telinit command. This command passes the conversion signal to INIT, telling it which runlevel to switch to. Run levels 0, 1, and 6 are reserved for the system's dedicated runlevel. Run level 0 is used to shut down, run Level 6 is used to restart, and run Level 1 is used to bring the computer into single user mode. The run level S is not used directly by us, but is called when some executable script is run at run Level 1 o'clock.

In this command, different parameters can be added for different purposes. such as the Shutdown–k command, is not a real shutdown, but just send a warning signal to each login (including remote login users). It is a good practice for system administrators to use this command to inform other logged-in users before shutting down the system. In addition, sometimes the Linux system will be like the Windows system, after the system shuts down and does not actively shut down the power. You can use this command shutdown–h to explicitly instruct the system to turn off the power at the same time after shutting down the machine. It is important to note that this command, like the halt shutdown command, invokes the GETUID system process to determine whether the current user is the root user. If it is, continue with the rear shutdown action, or exit the command directly if the current user is a normal user.


Linux shutdown command

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.