How To Determine The Current Runlevel In Linux [Quick Tip]

What is run level?

If you are new to the Linux environment then the term runlevel may be new to you, so I will first try to clear what the term runlevel in Linux/Unix environment refers to. Runlevel in Linux or Unix refers to a mode of operation of the operating system, essentially dictating the system’s behavior. Conventionally, seven runlevels exist, numbered from zero to six, although users may use runlevel up to ten, from zero to nine. Each runlevel serves a specific purpose and remember that only one “runlevel” is executed on bootup and runlevel are not executed sequentially. For example, either runlevel 2 or 3 or 5 is executed, and not 2 then 3 then 5.

If I speak in more technical terms, the init process is the first non-kernel process that is started, and therefore you will find that it always gets the process ID number of 1. You can find it using the top command in the terminal. init reads its configuration file, /etc/inittab, and then determines the runlevel where it should start. A runlevel of initdefault is selected if it exists otherwise you are prompted to supply a runlevel value.

The different runlevel values are as follows:

  • 0 = Halt the system
  • 1 = Enter single-user mode (no networking is enabled)
  • 2 = Multiuser mode, but without NFS
  • 3 = Full multiuser mode (normal operation)
  • 4 = Unused
  • 5 = Same as runlevel 3, except that it uses the X Window System to login rather than the text-based login system
  • 6 = Reboot the system

The exact setup of these configurations will vary from different operating system to operating system, and from one Linux distribution to another. When installing Linux, it is best to consult that distribution’s available user guides. In standard practice, when a computer enters runlevel zero, it halts, and when it enters runlevel six, it reboots. Default runlevels are typically 3 or 5.

How to determine the current run level?

There are different ways of finding the current runlevel in Linux. Two of them are as follows:

$ who -r

You can also use the option --runlevel instead of -r.

Linux has another command called runlevel which also prints the current runlevel.

$ runlevel

If you know about other commands that also prints the current runlevel, do share with us through comments below.

You may also like...