Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the shutdown and restart commands for Linux systems?

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the shutdown and restart commands of the Linux system?" interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the shutdown and restart commands of the Linux system?"

1 、 sync

Sync:flush file system buffers .

The function of the sync command is to flush the cache of the file system and write data synchronously to the hard disk.

The necessity of executing sync commands: in a computer, the data processed by 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 to memory. If the data is frequently exchanged between memory and hard disk, the system performance will be greatly reduced, so in order to speed up the data reading speed, by default Some of the data that has been loaded in memory will not be written back to the hard disk directly, but will be temporarily stored in memory first. If you shut down or restart the computer, the data temporarily stored in memory may be lost. The correct way is to execute the sync command first and execute it several times more to ensure that the data is written to the hard disk. In fact, some shutdown commands also perform sync operations by default.

2 、 shutdown

The shutdown command is used to safely shut down the Linux system. Some users will turn off the Linux by directly disconnecting the power supply, which is very dangerous. Because Linux is different from Windows, there are many processes running in the background, so forced shutdown may cause the data loss of the process, make the system in an unstable state, and even damage the hardware equipment.

When the shutdown command is executed, all logged-in users are notified that the system is about to shut down, and the login instruction is frozen, that is, new users can no longer log in to the system. Using the shutdown command, you can shut down the system directly, delay it for a specified time, or restart it. Delaying the shutdown of the system at a specified time allows users time to save files that are currently being processed and to close open programs.

Shutdown:bring the system down .

The syntax format is as follows:

The code is as follows:

Shutdown [OPTIONS]... TIME [MESSAGE]

Several parameters--

-k: it is not a real shutdown, but a warning message is sent. Login is no longer allowed at this time.

-c: cancel the shutdown instruction that is already in progress. At this point, the TIME parameter does not have to be selected. MESSAGE is the first parameter, which is optional.

-r: reboot after stopping the system service.

-h: halt or powweroff after stopping the system service.

-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 required and can be in a variety of formats. Now means immediate execution is equivalent to the case where the parameter is 0, such as 20:20 indicates the specific time for the execution of the command, and 20 indicates the execution of the command after 20 minutes.

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

0: shut down the system

1: single-user mode, if you execute directly without specifying the-h or-r parameters for the shutdown command, it will be switched to this run level by default

2: multi-user mode (NFS is not supported)

3: multi-user mode (supports NFS), which is commonly used.

5: multi-user mode (GUI mode)

6: restart the system

3 、 reboot 、 halt 、 poweroff

The syntax format is as follows:

Reboot [OPTIONS]... [REBOOTCOMMAND]

Halt [OPTIONS]...

Poweroff [OPTIONS]...

Several parameters--

-f: as described above, shutdown (8) will not be called.

-p: specified as the halt command, which has the same effect as poweroff.

-w: don't call shutdown (8) and reboot (2), just write the shutdown time record to / var/log/wtmp.

-verbose: outputs detailed command execution information.

Reboot (8), halt (8), poweroff (8): reboot or stop the system, these three commands are similar, and when looking for man, they are in the same page8. When the command is executed with the parameter "- f" or runlevel at 0: 6, the system call reboot (2) will be activated (the REBOOTCOMMAND parameter will be passed) and the system will be restarted directly, otherwise the shutdown (8) will be called, and the REBOOTCOMMAND parameter will not be passed. The shutdown time record is first written to / var/log/wtmp before calling reboot (2).

Halt shutdown command

Halt is the simplest shutdown command, which actually invokes the shutdown-h command. When halt is executed, the application process is killed, and the kernel is stopped after the file system write operation is complete.

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

[- f] forced shutdown or restart without calling shutdown

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

[- p] call poweroff when shutting down, which is the default option

Reboot linux restart command

Reboot works like halt in that it restarts, while halt shuts down. Its parameters are also similar to halt.

Poweroff

It is only supported by some pan-UNIX/LINUX systems, and 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 switch the running level of the system, and the switching is done immediately. The init 0 command is used to immediately switch the system runlevel to 0, that is, shutdown, and the init 6 command is used to switch the system runlevel to 6, that is, to restart.

There are seven execution levels of Linux, that is, run level ranges from 0 to 6, where run level 0 means shutdown, run level 6 means restart, and the command to switch run level is init, as shown below:

The code is as follows:

$init 0

$init 6

Init 0 can be powered off and init 6 can be restarted.

At this point, I believe that everyone has a deeper understanding of "which Linux system shutdown and restart commands", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report