Detailed Linux shutdown command

Abstract:        Some commonly used shutdown/restart commands under linux include shutdown, halt, reboot, and init. They can all achieve the purpose of restarting the system, but the internal working process of each command is different. Through the introduction of this article, I hope you Various shutdown commands can be used more flexibly.

      Some common shutdown/restart commands under linux include shutdown, halt, reboot, and init, all of which can achieve the purpose of restarting the system, but the internal working process of each command is different. Through the introduction of this article, I hope you can be more Flexible use of various shutdown commands.

1.shutdown

      (Strictly speaking, you can use the) shutdown command to safely shut down the system. Some users will use direct power off to shut down linux, which is very dangerous. Because linux is different from windows, there are many processes running in the background, so forced shutdown may cause data loss of the process, make the system in an unstable state, and even damage hardware devices in some systems.

      And using the shutdown command before the system shuts down, the system administrator will notify all logged in users that the system will be shut down. And the login command will be frozen, that is, new users can no longer log in. It is possible to shut down directly or delay the shutdown for a certain period of time, and it is also possible to restart. This is determined by all processes (process) will receive the signal sent by the system (signal). This gives programs like vi time to store the document currently being edited, while programs like mail and news can leave normally, and so on. 

      shutdown does its job by sending a signal to the init program, asking it to change the runlevel. Runlevel 0 is used to halt [halt], runlevel 6 is used to reactivate [reboot] the system, and runlevel 1 is used to bring the system into a state where administrative work can proceed: this is the default, assuming no -h There is also no -r parameter to shutdown. To understand what actions are taken during a shutdown (halt) or reboot (reboot), you can see the information about these runlevels in the file /etc/inittab.

Description of the shutdown parameter: 

2.halt - the simplest shutdown command

In fact, halt is to call shutdown -h . When halt is executed. Kill the application process and execute the sync system call. The kernel is stopped when the filesystem write operation is complete.

Parameter Description: 

3.reboot

reboot works almost the same as halt, but it causes the host to reboot. And halt is shutdown. Its parameters are similar to halt.

4.init

      init is the ancestor of all processes and its process number is always 1. So sending the TERM signal to init will terminate all user processes, daemon processes, etc. shutdown uses this mechanism. init defines 8 runlevels, init 0 is shutdown, init 1 is restart. About init can be a long story, so I won't describe it here. (Additionally, you can use init 0 for graceful shutdown and init 6 for graceful restart)

There are also telinit commands that can change the run level of init. For example, telinit -iS can make the system enter single-user mode without the information and wait time when using shutdown.

​​​​​​​

Original link

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326567385&siteId=291194637