Linux System Shutdown Command Difference and Usage Detailed Explanation

  • 2021-08-31 09:52:10
  • OfStack

What are the Linux system shutdown commands? Liangxu tutorial network answers for you! Friends who are familiar with linux should know that the shutdown commands commonly used in linux system are: shutdown, halt, poweroff, init; The restart command is: reboot. The following article mainly introduces some commonly used shutdown commands and the differences and specific usage between various shutdown commands.

Here are some common shutdown commands

1. halt shuts down immediately

2. poweroff shuts down immediately

3. shutdown-h now is shut down immediately (used by root users)

4. shutdown-h 10 shutdown automatically after 10 minutes

Note: If the shutdown is set through the shutdown command, you can cancel the restart with the shutdown-c command.

Restart command:


shutdown -r now  Restart immediately (root User use )
shutdown -r 10  Pass 10 Automatic restart in minutes (root User use )
shutdown -r 20:35  At the time of 20:35 Time to restart (root User use )

Note: If the restart is set through the shutdown command, you can cancel the restart with the shutdown-c command.

Let's follow this site of Liangxu Tutorial Network to see the differences between these specific shutdown commands of linux and their respective uses

1. shutdown Secure Shutdown Command

For shutdown command, it is a safe command recommended by everyone, and shutdown or restart can be completed through the cooperation of parameter-h or-r. However, on an linux system, you can only use this command if you have root privileges. Therefore, although everyone recommends using this command, it is really inconvenient to use: Do you want to use this command? Get root permission first. When shutdown executes shutdown, it sends a signal to init asking it to change its operation level, so as to shut down. Shutdown or restart is actually an adjustment of the run level, so we can also use init to directly adjust the run level for shutdown or restart. When this command is used, the machine is shut down or restarted immediately. It also requires root permission.

So why is the shutdown command safely shutting down the system?

In practice, some users will turn off linux by directly cutting off the power supply, which is 10 points dangerous. Because linux is different from windows, there are many processes running in its background, so forced shutdown may cause data loss of processes and make the system in an unstable state. Even in some systems, hardware devices will be damaged. When the shutdown command is used before the system is shut down, the system administrator will inform 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 1 fixed time before shutting down, and it is also possible to restart. This is determined by the fact that all processes (process) receive a signal from the system (signal).
shutdown performs its job by sending a signal (signal) to the init program asking it to change runlevel. runlevel 0 is used to shut down (halt), runlevel 6 is used to reactivate (reboot) the system, and runlevel 1 is used to put the system into a state where administrative work can be carried out, which is preset. Assume that there is no-h and no-r parameter for shutdown. What do you do during a shutdown (halt) or a reboot (reboot)? You can see the information about runlevels in this document/etc/inittab.

shutdown parameter description:

[-t] Before changing to another runlevel, tell init how soon to shut down. [-r] Restart Calculator. [-k] does not really shut down, just sends a warning signal to each login (login). [-h] Power off after shutdown (halt). [-n] Shut down without init. The use of this option is discouraged, and the consequences of this option are often not always what you expect. [-c] cancel current process cancels the shutdown program that is currently running. So of course, this option has no time parameter, but it can be entered 1 message for interpretation, and this message will be sent to each user. [-f] Ignore fsck when restarting the calculator (reboot). [-F] Force fsck when Calculator (reboot) is restarted. [-time] Sets the time before shutdown (shutdown).

2. halt's simplest shutdown command

When the halt command is used to shut down, the actual call is shutdown-h. When halt executes, it kills the application process, and when sync system calls are executed, the file system writes stop the kernel.

halt Parameter Description:

[-n] Prevents sync system calls, which are used after the root partition is patched with fsck to prevent the kernel from overwriting patched superblocks with older versions of superblocks (superblock). [-w] is not really a restart or shutdown, just writing wtmp (/var/log/wtmp) records. [-d] does not write wtmp records (included in option [-n]). [-f] forced shutdown or restart without calling shutdown. [-i] Shut down all network interfaces before shutdown (or restart). [-p] This option is the default. Is to call poweroff on shutdown.

3. Common shutdown commands for poweroff

As for poweroff, it is said on the Internet that it is the link of halt command, and its basic usage is similar to halt, so I won't say much here.

4.init

init is the ancestor of all processes, and it is one of the indispensable programs in the operation of Linux system. Its process number is always 1, so sending TERM to init will terminate all user processes, daemons, etc. shutdown uses this mechanism. init defines eight run levels (runlevel), init 0 for shutdown and init 1 for restart.

5. reboot restart command

reboot works much like halt1. However, it causes the host to restart, while halt is shut down. Its parameters are similar to those of halt.

The above is the Linux system shutdown commands between the differences and usage details, more about the Linux system shutdown commands between the differences and their respective usage of information please pay attention to other related articles on this site!


Related articles: