Linux running mode: Runlevel detailed analysis

Source: Internet
Author: User
Linux running mode: Runlevel detailed analysis-Linux general technology-Linux programming and kernel information, the following is a detailed description. The linux operating system has to go through several different stages from the start to the completion of the start. These stages are called runlevel. Similarly, when the linux operating system is shut down, it has to go through several different runlevels, next we will prepare to introduce runlevel in detail and show you some tips to avoid unnecessary Restart for your linux system.

Runlevel can be regarded as the system status and image. You can think of runlevel as Normal, safemode, and Command prompt only in Microsoft windows. To access each runlevel, you need to start or close a series of services. These services are stored in the/etc/rc. d/rc? directory as initialization scripts ?. D/or/etc/rc ?. Under d (? Indicates the serial number of runlevel ).

In most linux releases, there are usually eight runlevels

Runlevel System State
0 Halt the system
1 Single user mode
2 Basic multi user mode
3 Multi user mode
5 Multi user mode with GUI
6 Reboot the system
S, s Single user mode

In most Desktop linux systems, the default runlevel is 5, while in most server versions, the default runlevel is 3, and in most server versions, the default runlevel is 3, runlevel 1 and 2 are rarely used in addition to debugging. runlevel s and S are not directly used by users, but used to prepare for Single user mode.

The linux operating mode has the following advantages over the windows Startup Mode: You can use it when the system is idle. the init tool switches the runlevel you are currently using. In addition, when you shut down or start the linux system, you can switch your runlevel without knowing it. The system shutdown process needs to call runlevel (0 or 6) to close all running processes.

Display current running mode

When you get started, you may be curious about the previous and current running modes. The runlevel command can be used to display the information:

$/Sbin/runlevel

3 5

The runlevel command output indicates that the initial running mode is 3, and the current running mode is 5.

Switch Operation Mode

Use the telinit command (root User) to switch the running mode ):

$/Sbin/telinit

Generally, the purpose of switching the running mode is to restart some application processes, such as XFree86. Switching the running mode from 5 to 3 will terminate XFree86 and all processes related to it, then switch the running mode to 5, and XFree86 can be started very cleanly. Before doing this, make sure that all the work in XFree86 has been saved. Use the root user:

$/Sbin/telinit 3

$/Sbin/telinit 5

After you type a command, your screen may display information about the service start or stop.

Add startup service in Running Mode

To add a startup service in a running mode, you must first create a STARTUP script for the service and place it in/etc/rc. d/init. d or/etc/init. d/(depending on your linux version). to associate the startup script with the running mode, you need to create a directory in the running mode with/etc/rc. d/init. d/The symbolic link of the startup script. the prefix of the file name is generally SXX and XX is a number. This number is used to control the service startup sequence in this running mode. The script is executed in ascending order of numbers, that is, the smaller the number, the more advanced the execution. The following is an example of adding the startup service in running mode:

$ Cp myservice/etc/rc. d/init. d/

$ Ln-s/etc/rc. d/init. d/myservice/etc/rc3.d/S99myservice

In this way, the next time runlevel 3 is started, myservice will automatically start.

Start with a certain runlevel

You can customize the startup.

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.