Linux Proper shutdown method

Source: Internet
Author: User

For Windows users, it is often possible to press and hold the Power key for a few seconds before forcing the shutdown if they are having trouble. But for Linux, this is strongly not recommended.

Because the Windows (non-NT host system) system is single-user, "fake" multitasking, so even if your computer shuts down, it has no effect on others.

Linux is a multi-user, multi-tasking operating system, and each program (or service) is executed in the background. Therefore, you can not see the screen behind the fact that there may be many people at the same time on your host work, such as browsing the Web, send and receive email, etc., if you directly press the power to shut down the computer, then the other people's data may be interrupted, absolutely no words choke AH. In addition, the biggest problem is that an abnormal shutdown can cause file system corruption (because the system is too late to write data back into the file, so some services have a problem with the file). So under normal circumstances, the shutdown needs to pay attention to the following several things:

    • To view the usage status of the system
    • Notify online users when the shutdown
    • The correct shutdown command is used

1. View the system's usage status

Execute who this command to see who is currently online;

Execute netstat-a This command to view the online status of the network;

Execute ps-aux This command to view the programs executed in the background.

2. Notify online users when the shutdown

We can use the shutdown command to give other online users some time to end their work.

3. Use the correct shutdown command (sync, shutdown, reboot, Halt, Poweroff)

3.1 Data sync write to hard drive: Sync

To speed up the reading of data, some data that has already been loaded into memory in the Linux system will not be written directly to the hard disk. However, if your system does not shut down properly due to special circumstances (such as a power outage), the data is not properly updated because it has not been written to the hard disk.

Sync This command allows data to be written to the hard disk for data that has not been updated in memory. Therefore, this command is best performed several times before the system shuts down or restarts.

The current shutdown, reboot, halt and other commands are already in the shutdown before the sync this tool call, however, more than a few times is always more comfortable to perform.

[[Email protected]~]# sync; Sync

Note: The hard drive data updated by the general account only has its own data, and the root account can update the data in the entire system.

3.2 Recommended shutdown commands: shutdown

Because the Linux system shutdown/Restart is a significant system operation, only the root account can be carried out. The CentOS system allows the general account to be shut down or restarted when landing on a tty7 graphical interface.

If you use the Remote management tool, only the root account has permission to shut down or restart the computer.

Shutdown we often use the shutdown command, which notifies each process within the system and notifies some services within the system of the run level to shut down.

Shutdown can perform the following tasks:

    • Can freely choose the shutdown mode: Restart, shutdown or enter the single-user operation mode can be;
    • can set the shutdown time: can be set to shut down immediately, you can also set a specific time off the computer;
    • You can customize the shutdown message: Before shutting down, you can send the message you set to the online user;
    • You can just issue a warning message: Sometimes you may want to do some testing, but do not want to other user interference, or to clearly tell the user some time to pay attention to, this time can use shutdown to notify the user, but it is not really to shut down the machine;
    • You can choose whether you want to check the file system with FSCK

Syntax rules for shutdown:

(This is the simple version, more information can be executed command: [[email protected]~]# man shutdown Get]

[Email protected]~]# shutdown [OPTION] ... Time [MESSAGE]

OPTIONS:

-T: after-T plus number, that is, a few seconds after the shutdown;

-K: Just send a warning message out, not really shut down;

-R: Restart the system after the service is stopped (commonly used);

-H: Shut down the system after the service is stopped (commonly used);

-N: Not through the INIT program, directly to the shutdown function to shut down the machine;

-C: Cancels the shutdown command in progress;

Time: Specify when the system shuts down, the format includes: ' Now ', ' +m ', ' hh:mm ', that is immediately shut down, a few minutes after the shutdown, hh:mm time off;

It is important to note that the time parameter must be added to the command, otherwise the shutdown command will automatically jump to run Level 1 (single user maintained login).

Here are a few examples:

[Email protected]~]# shutdown-h Now

#常用关机命令, the system will be shut down immediately after execution, now equivalent to 0 of the situation;

[[Email protected]~]# shutdown-h 15:25

#系统在今天的15:25 will turn off the machine, if the current time is more than 15:25, the system will be shut down 15:25 the next day;

[[Email protected]~]# shutdown-h +10

#系统在10分钟之后自动关机;

[Email protected]~]# shutdown-r Now

#系统立刻重启;

[[Email protected]~]# shutdown-r +30 ' The system would reboot '

#系统在30分钟之后会重启 and display the following message ' The system would reboot ' to all online users;

[Email protected]~]# shutdown-k Now ' the system would reboot '

#系统立刻发出后面的消息 ' The system will reboot ' warns, but only warns, and does not shut down;

3.3 Restart, shutdown: Reboot, Halt, Poweroff

In fact, these three command calls function libraries are similar, so when you use the "man reboot" command, you will also show the use of three commands.

Since these commands can be shut down or restarted, what is the difference between them?

By default, these commands will do the same thing (because Halt will call shutdown first, and shutdown will call halt in the end).

Shutdown will shut down the services after each service has been started, and halt can shut down the hardware without regard to the current system health.

We usually just remember the two commands of reboot and shutdown.

Source: "Brother's Linux Private Cuisine" (third edition), "Linux command, editor and Shell Programming" (3rd edition)

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.