Detailed explanation of Linux shutdown command

Time:2022-1-23

The commonly used shutdown commands under Linux are: shutdown, halt, poweroff, init; The restart commands are: reboot. The following article mainly introduces some commonly used shutdown commands and the differences and specific usage between various shutdown commands.

First, let’s take a look at some commonly used shutdown commands under Linux

Shutdown command:

1. Halt shutdown immediately 2. Poweroff shutdown immediately 3. Shutdown – h now shutdown immediately (used by root user) 4. Shutdown – H automatically shuts down after 10 minutes. If the shutdown is set through the shutdown command, you can use the shutdown – C command to cancel the restart

Restart command:

1. Reboot 2. Shutdown – r now restart immediately (used by root user) 3. Shutdown – R 10 automatic restart in 10 minutes (used by root user) 4. Shutdown – R 20:35 restart at 20:35 (used by root user) if the restart is set through the shutdown command, you can cancel the restart with the shutdown – C command

Under Linux, some commonly used shutdown / restart commands are shutdown, halt, reboot, and init, which can achieve the purpose of restarting the system, but the internal working process of each command is different.

Linux CentOS restart command:

1、reboot
2. Shutdown – r now restart immediately (used by root)
3. Shutdown – R automatic restart in 10 minutes (used by root user)
4. Shutdown – R 20:35 restart at 20:35 (used by root)

If the restart is set through the shutdown command, you can cancel the restart with the shutdown – C command

Linux CentOS shutdown command:

1. Halt, turn it off now
2. Poweroff power off immediately
3. Shutdown – h now shut down immediately (used by root user)
4. Shutdown – H automatic shutdown after 10 minutes

If the shutdown is set through the shutdown command, you can use the shutdown – C command to cancel the restart

1.shutdown
The shutdown command safely shuts down the system. Some users will turn off Linux by directly disconnecting the power supply, which is very dangerous. Because Linux is different from windows, there are many processes running in the background, so forced shutdown may lead to process data loss, make the system in an unstable state, and even damage the hardware equipment in some systems.

Using the shutdown command before the system shuts down, the system administrator will notify all logged in users that the system is about to shut down. And the login instruction will be frozen, that is, new users can no longer log in. It is possible to shut down directly or delay for a certain time, and it may also be restarted. This is determined by the fact that all processes will receive the signal sent by the system. This gives programs like VI time to store documents that are currently being edited, while programs like mail and news can leave normally, and so on.

The job of shutdown is to send a signal to the init program to change the runlevel. Runlevel 0 is used to shut down [halt], runlevel 6 is used to reactivate [reboot] the system, and runlevel 1 is used to make the system enter the state where management work can be carried out; this is preset, assuming that there is no – H or – R parameter for shutdown. To find out what actions are taken during a halt or reboot, you can see the runlevels related information in the file / etc / inittab.
  
Shutdown Parameter Description:
[- t] before changing to other runlevels, tell init how long it will shut down.
[- R] restart the calculator.
[- k] does not really shut down, but sends a warning signal to each login.
[- H] turn off the power [halt] after shutdown.
[- n] do not use init, but shut down by yourself. This option is discouraged, and the consequences of this option are often not always what you expect.
[- C] cancel current process cancels the currently executing shutdown process. So of course, this option has no time parameter, but you can enter a message to explain, and this message will be sent to each user.
[- F] ignore fsck when restarting the calculator [reboot].
[- F] force fsck when restarting the calculator [reboot].
[- time] sets the time before shutdown.

2. Halt —- the simplest shutdown command

In fact, halt calls shutdown – H. When halt is executed, the application process is killed and the sync system call is executed. After the file system write operation is completed, the kernel will be stopped.
Parameter Description:
[- n] prevent sync system calls. It is used after repairing the root partition with fsck to prevent the kernel from overwriting the repaired superblock with the old version of superblock.
[- w] is not a real restart or shutdown, but a wtmp [/ var / log / wtmp] record.
[- D] do not write wtmp record [included in option [- n]].
[- F] forced shutdown or restart without calling shutdown.
[- I] turn off all network interfaces before shutting down [or restarting].
[- P] this option is the default. Is to call poweroff when shutdown.

3.reboot
The working process of reboot is almost the same as that of halt, but it causes the host to restart, and halt shuts down. Its parameters are not much different from halt.

4.init
Init is the ancestor of all processes. Its process number is always 1, so sending term signal to init will terminate all user processes and daemons. Shutdown uses this mechanism. Init defines 8 runlevels. Init 0 is shutdown and init 1 is restart. Init can be a long story, which will not be described here. In addition, the telinit command can change the operation level of init. For example, telinit – is can make the system enter single user mode, and can not get the information and waiting time when using shutdown.

5. Reboot restart command

The working process of reboot is almost the same as that of halt. However, it causes the host to restart, and halt is shutdown. Its parameters are not much different from halt.

Recommended Today

Burst the liver for three days, learn SCSS – read this article is enough

preface Today is different from the past. We can only cut pictures by ourselves! stayJavasScripWhen the frame was flying all over the sky, the front end was one of the three board axesCSSAlso gushed forward and backwardSass、Less 、StylusEtcCSSPreprocessing framework. Today we are going to talk about the big brotherSassUpgraded version ofScss,ScssIt provides us with a […]