Correct Shutdown Method in Linux

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

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"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324730714&siteId=291194637