1. Five Linux restart commands
1、shutdown
2、poweroff
3、init
4、reboot
5、halt
2. Specific description of five restart commands
shutdown
reboot
Some commonly used shutdown/reboot 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 can use various shutdown commands more flexibly.
The shutdown command safely shuts down the system. Some users will use the method of directly disconnecting the power to turn off Linux, which is very dangerous. Because Linux is different from Windows, there are many processes running in the background, forced shutdown may lead to data loss of the process, causing the system to be in an unstable state, and even damage hardware devices in some systems. If you use 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, the new user can no longer log in. It is possible to shut down directly or delay the power down for a certain period of time, and it may also restart. This is a signal sent by all processes [process].
Decided. This gives programs like vi time to store documents currently being edited, while programs like mail and news can leave normally, etc.
shutdown performs its job to send a signal to the init program, requiring it to change the runlevel.
Runlevel 0 is used to shut down [halt], runlevel 6 is used to reactivate the system, and runlevel 1 is used to let the system enter a state where management work can be carried out. This is a preset, assuming there is no -h and no -r parameter to shutdown. To understand what actions were done during the shutdown or reboot, you can see these runlevels-related information in this file /etc/inittab.
shutdown parameter description:
[-t] Before changing to other runlevels, tell init how long to shut down.
[-r] Restart the calculator.
[-k] It doesn't really shut down, it's just a warning signal
Each login is login.
[-h] Turn off the power after shutting down [halt].
[-n] Don't need init, but shut down the phone 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 program. So of course this option does not have a time parameter, but you can enter a message to explain, and this information will be sent to each user.
[-f] Ignore fsck when restarting the calculator [reboot].
[-F] Force fsck when restarting the calculator [reboot].
[-time] Set the time before shutdown.
----The easiest shutdown command
In fact, halt is to call shutdown -h. When halt is executed, it kills the application process and executes a sync system call. The kernel will be stopped after the file system write operation is completed.
Parameter description:
[-n] Prevent sync system calls, which is used to patch the root partition with fsck to prevent the kernel from overwriting the patched superblock with the old version of superblock.
[-w] It's not really a restart or shutdown, it's just a write
wtmp [/var/log/wtmp] record.
[-d] Do not write wtmp record [included in option [-n]].
[-f] Force shutdown or restart without shutdown.
[-i] Turn off all network interfaces before shutting down [or restarting].
[-p] This option is the default option. It is to call poweroff when shutting down.
The working process of reboot is almost the same as halt, but it triggers the host to restart, while halt shuts down. Its parameters are not much different from halt.
init is the ancestor of all processes, and its process number is always 1, so sending a TERM signal to init will terminate all user processes, daemon processes, etc. shutdown uses this mechanism. init defines 8 runlevels, init 0 is shutdown and init 1 is restart. You can talk about init in a long way, and I won’t describe it here. There is also the telinit command that can change the running level of init. For example, telinit -iS can enable the system to enter single-user mode and cannot obtain the information and waiting time when using shutdown.
The above are the five restart commands in Linux introduced to you by the editor. I hope they will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!