Explain the usage of shutdown and restart commands in Linux system

Time:2020-8-13

shutdown
Shutdown shut down the system in a safe way. All login users can see the shutdown message, and login (1) will be blocked. You can specify immediate shutdown or system shutdown after a certain delay. All processes will receive SIGTERM signals. This allows time for programs such as vi (1) to store files in the editing state, mail and news program processes to properly clear all data in the buffer pool, and so on. Shutdown is achieved by notifying the init process to change its run level. Runlevel 0 is used to shut down the system, runlevel 6 is used to restart the system, and runlevel 1 is used to make the system enter the state of executing system management tasks. If the – H or – R flag is not given, this is the default working state of shutdown command. Please refer to the corresponding run level column in the / etc / inittab file for the specific operation of shutdown or restart.

Options

-a
Use / etc/ shutdown.allow To verify your identity.
-t sec
It tells init (8) to send a warning signal and delay (SEC) seconds before switching to other operation levels, and then send a kill signal.
-k
It is not a real shutdown, only a warning message is displayed to everyone.
-r
Restart.
-h
Shut down.
-n
[degraded] does not call init (8) program for shutdown operation, but by itself. Users are not recommended to use this shutdown method, and its results are generally not what you want.
-f
Skip disk detection on restart.
-F
Force disk detection on restart.
-c
Cancels the shutdown process that is running. It is not possible to specify the time parameter for this option, but you can enter an explain message on the command line to explain it to all users. (the normal shutdown instruction can be interrupted by pressing the “+” sign)
time
Shutdown time.
warning-message
Messages sent to all users.

There are many formats for the time parameter. First, it can be an absolute time in HH: mm format, where HH refers to hours (one to two digits) and mm refers to minutes (two digits). The second is the + m format, where m is the number of minutes to wait. Now is an alias for + 0.
If shutdown uses a delay when it is called, it will automatically create an advisory file / etc / nologin, which prevents login (1) from allowing new users to log in, unless shutdown aborts unexpectedly before signaling init (that is, it is cancelled or something goes wrong). It will delete the file before calling init to change the runlevel.
-f
The logo means’ fast restart ‘. This creates an advisory file / FastBoot that will be detected when the system restarts. The startup script RC will detect whether such a file exists, and if so, fsck (1) will not be run again because the system is shut down in a normal way. After that, the boot process removes / FastBoot.
-F
The flag means’ force fsck ‘. This creates an advisory file / forcefsck, which will be detected when the system restarts. The startup script RC will detect whether the file exists. If so, it will run fsck (1) and add a special ‘force’ flag to check even the normally unloaded file system. After that, the startup process removes / forcefsck.

-The N flag causes shutdown to shut down all running processes instead of calling the init program. Shutdown will then shut down quotas, accounting, and swap partitions, and unmount all file systems.

For example:

Copy code

The code is as follows:

[ [email protected]linux ~]#Shutdown – h now
[ [email protected] ~]#Shutdown – h 23:00 ා shut down at 11:00 p.m
[ [email protected] ~]#Shutdown – r now ා restart
[ [email protected] ~]#Shutdown – R + 30 ‘reboot now’? Restart after 30 minutes and prompt reboot now

halt
Usage:
Halt [- n] [- w] [- D] [- F] [- I] [- P] Note: if the runlevel of the system is 0 or 6, the system will be shut down; otherwise, it will be replaced by the shutdown instruction (plus the – h parameter)

Parameters:
-Do not write data to the hard disk before shutting down
-W: it doesn’t really shut down. It just writes the records to the / var / log / wtmp file
-D: do not write records to / var / log / wtmp file (- n parameter contains – D) – F: force shutdown, do not call shutdown command
-I: stop all network related devices before shutting down
-P: when the power is off, do the power off action

For example:

Copy code

The code is as follows:

[ [email protected] ~]#Shut down

reboot
Function Description: restart.

Grammar: dreboot [- dfinw]

Supplementary note: execute the reboot command to stop and restart the system.

Parameters:
– d do not write data to the log file / var / TMP / wtmp when rebooting. This parameter has the effect of the “- n” parameter.
– f forces a reboot without calling the shutdown command.
– I close all network interfaces before restarting.
– n do not check for open programs before restarting.
– W only tests, does not really restart the system, only writes the data of the restart to the wtmp log file in the / var / log directory.
For example:
 

Copy code

The code is as follows:

[ [email protected] ~]#Reboot ා restart

Recommended Today

How to share queues with hypertools 2.5

Share queue with swote To realize asynchronous IO between processes, the general idea is to use redis queue. Based on the development of swote, the queue can also be realized through high-performance shared memory table. Copy the code from the HTTP tutorial on swoole’s official website, and configure four worker processes to simulate multiple producers […]