The shutdown and restart commands commonly used in Linux have Shutdown, Halt, Reboot, and Init, they can achieve the purpose of shutdown and restart, but the internal work process of each command is different, and will be introduced one by one.
The shutdown shutdown command is used to secure to shut down the Linux system. Some users will use them directly to turn off the power to shut down Linux, which is very dangerous. Because Linux is different from Windows, there is a lot of processes in the background, so that it mandatory shutdown may cause data loss of the process, so that the system is in unstable state, or even damage the hardware device. When executing the shutdown command, the system will notify all the logged-in user systems will be turned off, and the login directive is frozen, that is, the new user can no longer log in to the system. Use the shutdown command to close the system directly, or delay the specified time and then turn off the system, and you can restart. Delay the specified time to close the system, allowing the user to have time to store the file currently processing and closing the already opened program. Some parameters of the shutdown command are as follows: [-t] Specifies that the shutdown system after how long is the system [-r] restart system [-k] does not really shut down, just send a warning signal [-h] shut down system for each login user ( Halt) The working element of the shutdown command is to send the signal (Signal) to the init program, requiring it to switch the system's run level (Runlevel). The system's running level includes: 0: Close system 1: Single user mode, if not specifying the -h or -r parameter for the shutdown command, the default will switch to this level 2: Multi-user mode (not support NFS) 3: Multi-User Mode (Support NFS), generally used this range 5: Multi-user mode (GUI mode) 6: Restarting the system
2. Halt Halt is the easiest shutdown command, which is actually calling the shutdown -h command. When HALT is executed, kill the application process, and the kernel will stop after the file system is written. The partial parameters of the HALT command are as follows: [-f] Call Poweroff when turning off all network interfaces [-p] when turning off or restarting [-i] is turned off or restarted to turn off all network interface [-p] to turn off all network interfaces [-p] to turn off all network interfaces [-p]. This option is the default option
3. The work process of Reboot Reboot is similar to HALT, and its role is restarted, and HALT is shutdown. Its parameters are also similar to HALT.
4. Init init is a ancestors of all processes, and its process number is always 1. INIT is used to switch the system's running level, and the operation of switching is complete immediately. The init 0 command is used to switch the system run level to 0, ie shutdown; the init 6 command is used to switch the system run level to 6, that is, restart.