How to Change the Start Order of Processes in Linux
The Linux operating system is powerful and flexible, able to run in several different modes of operation called run levels. When a Linux system starts, a function called “init” is used to configure the system into one of the run levels. Upon entering a run level, init uses a series of scripts to perform tasks and launch processes. You can change the order in which processes are launched by changing the order that init accesses the scripts for a particular run level.
Open the terminal and type “su -” or “sudo su -” to log into the root user account. Enter your password when prompted.
Enter “cd /etc” to switch directories. Use “ls -d rc.d” to locate the run level script directories. If the only directory listed is “rc.d” then switch to that directory and run “ls -d rc.d” again. There should be a list of directories from rc0.d to rc6.d, each containing the symbolic links that are executing at that run level. Note that only rc2.d through rc5.d are changeable; the others are reserved.
Switch to the desired run level directory using “cd rc#.d” replacing "#" with the desired run level. The default run level will depend on the specific system and the distribution of Linux being used. Commonly, run level 5 is used for graphical desktop modes.
Locate the process you want to reorder. You can view the symbolic links in current run level directory by using the “ls” command. Symbolic links that execute a process begin with “S” and are followed by two numbers. Init will run these scripts in sequential order based on these numbers. For example, if there is a link named S10exampleproc1 and another named S15exampleproc2, S10examplepoc1 will be loaded first.
Rename the symbolic link to change the process's start order. Use the “mv” command to rename the link. For instance, if you want to change S15exampleproc2 to load just before S10exampleproc1, use “mv S15exampleproc2 S09exampleproc2” to rename the link.
- If two links in the same run level directory have identical numbers, the processes will be loaded alphabetically. The default run level depends on the specific Linux distribution. The “who -r” displays the run level the system is currently operating, and the “init #” changes the current run level, replacing the "#" with the desired level. Note, run level 6 will restart the computer and run level 1 will halt the operating system.
- Use extreme caution when adjusting start orders. A bad start order can cause the system to become unstable or unable to load the operating system.
C.A. Rubino has spent more than 30 years amassing an unusual educational background including a doctorate in metaphysical science, a Master of Arts in Jungian psychology and certification as a Karuna Ki/Reiki master. Currently, he writes for various publications, specializing in religion and spirituality along with topics on alternative health and computer technology.