Why shutdown is important in Linux
- Asynchronous disk/memory data transfer mode
- Multiplayer multitasking environment
In Linux, every program is executed in the background, so many people are actually working on the host computer at the same time behind the invisible screen. If it is shut down at this time, other people's data may be interrupted.
In addition, in a computer, all data must be read into the memory before it can be processed by the CPU. In a Linux system, in order to speed up data reading, by default, some data that has been loaded into memory will not be directly written back to the hard disk, but will be temporarily stored in the memory first. If it is turned off at this time, the data will not be written to the hard disk, which will cause the data to be updated abnormally.
What to do before shutting down
Check the usage status of the system
- who: who is currently online ( who command explains )
- netstat -a: network connection status ( netstat command explanation )
- ps -aux: program executed in the background ( ps command explanation )
Notify online users of when to shut down
- shutdown -k now 'This system will reboot' (shutdown command will be introduced later)
Write data to hard disk synchronously
- sync
Shutdown and restart commands
shutdown
shutdown [-t sec] [-arkhcfF] time(min) [warning message]
parameter:
- -t sec: add seconds after -t, shutdown after a few seconds
- -k: just send a warning message
- -r: restart the system service after stopping it
- -h: Shut down the system after stopping the system service
- -n: Shut down directly with the shutdown function without going through the init program
- -f: Force to skip fsck disk check after shutdown and power on
- -F: Force fsck disk check after system restart
- -c: Cancel the content of the shutdown command that is already in progress
example:
- shutdown -h 10 'I will shutdown after 10 mins
' - shutdown -h now shutdown
immediately - shutdown -h 20:25
The system shuts down at 20:25 - shutdown -r now
restart immediately - shutdown -k now 'This system will reboot'
only sends the parameter of the warning letter, the system will not be shut down
reboot
reboot [-nwdfi]
- -n : Do not write the memory data back to the hard disk before rebooting
- -w : don't actually reboot, just write the log to the /var/log/wtmp file
- -d : do not write the log to the /var/log/wtmp file (-d is included in the -n parameter)
- -f : Force reboot, do not call shutdown command
- -i : Stop all network related devices before rebooting
references
- "Brother Bird's Linux Private Kitchen"