Summary of shutdown and restart related commands for Linux systems

Source: Internet
Author: User
Tags file system

1, Sync

Sync:flush file system buffers.

Sync Command function: Refreshes the file system cache and writes data to the hard drive synchronously.

The need to perform the sync command: In a computer, the data processed by the CPU is first read into memory, and the data is often written back to the hard disk, but the speed of the hard disk is too slow compared with the memory, if the data is frequently exchanged between memory and hard disk, the system performance will be greatly reduced, so as to speed up the data reading speed By default, some data that has already been loaded in memory will not be written back directly to the hard disk. But in the memory of the first time, if the shutdown or restart the computer, there will be the memory of the data may be lost, the correct way is to execute the sync command, more than just a few times to ensure that the data written to the hard disk, In fact, some shutdown commands also perform the sync operation by default.

2, Shutdown

The shutdown command is used to securely shut down Linux systems. It is very dangerous for some users to turn off Linux by simply breaking the power off. Because Linux differs from windows in that it runs many processes in the background, forcing a shutdown can cause data loss in the process, leaving the system in an unstable state and even damaging hardware devices.

When the shutdown command is executed, all logged-in user systems are notified that the system will be closed and the login instruction is frozen, that is, the new user cannot log on to the system again. You can use the shutdown command to shut down the system directly, or you can delay the system at a specified time, or you can restart it. Delaying the system at a specified time allows the user time to store the files currently being processed and to close the programs that are already open.

Shutdown:bring the system down.

The syntax format is as follows:

The code is as follows:

shutdown [OPTIONS] ... time [message]

Several parameters--

-K: Instead of a real shutdown, send a warning message and no longer allow logon.

-C: Cancels the shutdown instruction already in progress, the time parameter does not have to select, the message is the first parameter, this parameter is optional.

-R: Reboot after the system service is stopped.

-H: Halt or Powweroff after the system service is stopped.

-H: Halt after the system service is turned off.

-P: Poweroff After the system service is turned off.

Note: The time of the shutdown command is a required parameter, in several formats, now means that the immediate execution is equivalent to the argument 0, and the form, like 20:20, specifies the timing of the execution of the command, as 20 indicates that the command is executed after 20 minutes.

The essence of the shutdown command is to send a signal (signal) to the INIT program, requiring it to switch the operating level of the system (RunLevel). The operating levels of the system include:

0: Shut down the system

1: Single-user mode, if executed directly without specifying the-h or-R parameter for the shutdown command, the default will switch to this run level

2: Multi-user mode (NFS not supported)

3: Multiuser mode (support for NFS), commonly used in this kind of running level

5: Multi-user mode (GUI mode)

6: Reboot the system

3, reboot, Halt, Poweroff

The syntax format is as follows:

Reboot [OPTIONS] ... [Rebootcommand]

Halt [OPTIONS] ...

Poweroff [OPTIONS] ...

Several parameters--

-F: With the above description, shutdown (8) is not invoked.

-P: Specified as the halt command, the effect is the same as Poweroff.

-W: Do not invoke shutdown (8) and reboot (2), but write shutdown time records to/var/log/wtmp.

–verbose: Output detailed command execution information.

Reboot (8), Halt (8), Poweroff (8): Reboot or stop the system, which is similar to the three commands, find the man when they are in the same page8. When the command is executed with either the parameter "-F" or the 0~6 RunLevel, the system call reboot (2) (the Rebootcommand parameter passes) is activated and the system is invoked directly or shutdown (8). The Rebootcommand parameter does not pass through at this time. Before reboot (2) is invoked, the shutdown time record is first written to the/var/log/wtmp.

Halt shutdown command

Halt is the simplest shutdown command, which is actually invoking the Shutdown-h command. When halt executes, the application process is killed, and the kernel is stopped when the file system write operation completes.

Some of the parameters of the halt command are as follows:

[-f] forced shutdown or reboot without calling shutdown

[-i] turn off all network interfaces before shutting down or restarting

[-p] Call Poweroff when shutdown, this option is the default option

Reboot Linux Restart command

Reboot's work process is similar to halt, and its role is to reboot, while Halt is shutdown. Its parameters are similar to those of halt.

Poweroff

Part of the pan-unix/linux system to support, Red Flag Linux is also applicable.

4. Init

Init is the ancestor of all processes, and its process number is always 1. Init is used to toggle the running level of the system, and switching is done immediately. The init 0 command is used to switch the system run level immediately to 0, the shutdown, and the init 6 command to switch the system run level to 6, or reboot.

There are seven levels of execution for Linux, from 0 to 6, where run level 0 is shutdown, and run Level 6 indicates a reboot, and the command to switch to run is init, as follows:

The code is as follows:

$ init 0

$ init 6

Init 0 can be shut down and Init 6 can be restarted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.