Detailed explanation of the differences and usages of Linux system shutdown commands

Detailed explanation of the differences and usages of Linux system shutdown commands

What are the shutdown commands for Linux systems? Liangxu Tutorial Network has the answers for you! Friends who are familiar with Linux should know that the shutdown commands we often use in Linux systems are: shutdown, halt, poweroff, init; the restart commands are: reboot. The following article mainly introduces some commonly used shutdown commands as well as the differences and specific uses of various shutdown commands.

The following are some of the more commonly used shutdown commands

1. Halt shuts down the computer immediately

2. Poweroff: shut down the computer immediately

3. shutdown -h now shuts down immediately (used by root user)

4. shutdown -h 10 automatically shuts down after 10 minutes

Note: If the shutdown command is used to set the shutdown, you can use the shutdown -c command to cancel the restart.

Restart command:

shutdown -r now Restart immediately (for root user)
shutdown -r 10 Automatically restart after 10 minutes (for root user)
shutdown -r 20:35 Restart at 20:35 (used by root user)

Note: If the restart is set by the shutdown command, you can cancel the restart with the shutdown -c command.

Next, let's follow the editor of Liangxu Tutorial Network to look at the differences between these specific shutdown commands in Linux and their respective uses.

1.shutdown safe shutdown command

As for the shutdown command, it is a safe command recommended by everyone. It can be used with the -h or -r parameter to complete shutdown or restart. However, in Linux systems, only those with root privileges can use this command. So, although everyone recommends using this command, it is really not very convenient to use: Do you want to use this command? Get root privileges first. Shutdown executes shutdown by sending a signal to init, asking it to change the running level to shut down the computer. Shutting down or restarting is actually adjusting the run level, so we can also use init to directly adjust the run level to shut down or restart. When this command is used, the machine is shut down or restarted immediately. It also requires root privileges.

So why is the shutdown command said to shut down the system safely?

In practice, some users will shut down Linux by directly cutting off the power supply, which is very dangerous. Because Linux is different from Windows, it has many processes running in the background, so forced shutdown may cause process data loss and put the system in an unstable state. In some systems, it may even damage hardware devices. By using the shutdown command before shutting down the system, the system administrator will notify all logged-in users that the system is about to shut down. And the login command will be frozen, that is, new users can no longer log in. It is possible to shut down the computer directly or delay it for a certain period of time, or it may be restarted. This is determined by the fact that all processes will receive signals sent by the system.
Shutdown performs its work by sending a signal to the init program, asking it to change the runlevel. Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put the system into a state where management work can be performed, which is the default. Assume that neither -h nor -r parameters are given to shutdown. Want to know what actions are taken during a halt or reboot? You can see information about these runlevels in the file /etc/inittab.

shutdown parameter description:

  • [-t] Tell init how long to wait before shutting down the system before changing to another runlevel.
  • [-r] Restart the calculator.
  • [-k] does not actually shut down the computer, but only sends a warning signal to each logged-in user.
  • [-h] Turn off the power after shutdown (halt).
  • [-n] Do not use init but shut down the system by itself. Use of this option is discouraged and may not always produce the results you expect.
  • [-c] cancel current process Cancel the shutdown process currently being executed. So this option certainly has no time parameter, but you can enter
  • A message of explanation will be sent to each user.
  • [-f] Ignore fsck when rebooting the computer.
  • [-F] Force fsck on reboot.
  • [-time] Set the time before shutdown.

2.halt The simplest shutdown command

When you use the halt command to shut down the computer, what is actually called is shutdown -h. When halt is executed, the application process will be killed, and the kernel will be stopped after the sync system call is executed and the file system write operation is completed.

halt Parameter Description:

  • [-n] Prevents the sync system call, which is used after patching the root partition with fsck to prevent the kernel from overwriting the patched superblock with the old version of the superblock.
  • [-w] does not actually restart or shut down the computer, but only writes a record to wtmp〔/var/log/wtmp〕.
  • [-d] Do not write wtmp records (included in option [-n]).
  • [-f] Force shutdown or reboot without calling shutdown.
  • [-i] Shut down all network interfaces before shutting down (or restarting).
  • [-p] This option is the default option. That is, poweroff is called when shutting down.

3.poweroff Common shutdown commands

As for poweroff, the Internet says it is a link to the halt command, and its basic usage is similar to halt, so I won’t go into details here.

4.init

Init is the ancestor of all processes and is one of the indispensable programs in Linux system operation. Its process number is always 1, so sending the TERM signal to init will terminate all user processes, daemons, etc. shutdown uses this mechanism. init defines 8 runlevels, init 0 is shutdown, init 1 is restart.

5. reboot command

The working process of reboot is almost the same as halt. However, it causes the host to restart, while halt causes the host to shut down. Its parameters are similar to halt.

The above is the detailed content of the differences and usage of the Linux system shutdown commands. For more information about the differences and usage of the Linux system shutdown commands, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of Linux shutdown command summary

<<:  MySQL transaction autocommit automatic commit operation

>>:  HTML table markup tutorial (38): Border color attribute of the header BORDERCOLOR

Recommend

Pure CSS implementation of radio and checkbox effect example

radio-and-checkbox Pure CSS to achieve radio and ...

Practical record of vue using echarts word cloud chart

echarts word cloud is an extension of echarts htt...

MySQL optimization query_cache_limit parameter description

query_cache_limit query_cache_limit specifies the...

How to migrate local mysql to server database

We can use the scp command of Linux (scp cannot b...

The concept of MySQL tablespace fragmentation and solutions to related problems

Table of contents background What is tablespace f...

Detailed tutorial on installation and configuration of nginx under Centos7

Note: The basic directory path for software insta...

CSS3 property line-clamp controls the use of text lines

Description: Limit the number of lines of text di...

Differences between ES6 inheritance and ES5 inheritance in js

Table of contents Inheritance ES5 prototype inher...

MySQL learning notes help document

View system help help contents mysql> help con...

Example verification MySQL | update field with the same value will record binlog

1. Introduction A few days ago, a development col...

Use of MySQL query rewrite plugin

Query Rewrite Plugin As of MySQL 5.7.6, MySQL Ser...

Javascript Basics: Detailed Explanation of Operators and Flow Control

Table of contents 1. Operator 1.1 Arithmetic oper...

JavaScript plugin encapsulation for table switching

This article shares the encapsulation code of Jav...