Skip to content

Managing Processes

The Linux kernel provides a load average which is a measurement provided as a rough gauge of how a system is performing and determine load over time.

The load average represents system load over time and determined by reporting how many processes are ready to run on a CPU, and how many processes are waiting for disk or network I/O to complete.

The uptime command is one method to display the current load average.

uptime
 09:34:00 up 1 day,  3:13,  2 users,  load average: 0.00, 0.00, 0.00

The three values for the load average represent the load over the last one, five, and fifteen minutes.

The lscpu command can help you determine how many CPUs a system has.

The top command also provides a dynamic real-time view of a running system. Use key 1 while in top displays all CPUs on a system.

Signals are software interrupts sent to a program to indicate that an event has occurred. Events that generate a signal can be an error, external event, or by use of a signal-sending command.

The kill command sends a signal to a process by PID number. Despite its name, the kill command sends any signal, not just those for terminating programs. You can use the kill -l command to list the names and numbers of all available signals.

 1) SIGHUP       11) SIGSEGV 
 2) SIGINT       12) SIGUSR2 
 3) SIGQUIT      13) SIGPIPE
 4) SIGILL       14) SIGALRM  
 5) SIGTRAP      15) SIGTERM 
 6) SIGABRT      16) SIGSTKFLT 
 7) SIGBUS       17) SIGCHLD 
 8) SIGFPE       18) SIGCONT    
 9) SIGKILL      19) SIGSTOP 
10) SIGUSR1      20) SIGTSTP

System administrators, however, are most familiar with number 9 the SIGKILL, which causes abrupt program termination.

Use the ps command to view running process IDs (PIDs) and then the kill command to terminate it.

ps -ef | grep firewall

root       771  ...output omitted...
# kill -9 771

Linux systems run more processes than there are processing units. A technique called time-slicing or multitasking is used by the operating system process scheduler to rapidly switch between processes on a single-core, giving the impression that multiple processes are running at the same time.

ps axo pid,comm,nice,cls --sort=-nice

Not all processes are equally important. Processes running with the SCHED_NORMAL policy can be given a relative priority. This priority is called the nice value of a process. The nice level values range from -20 (highest priority) to 19 (lowest priority). By default, processes inherit their nice level from their parent, which is usually 0.

Without options, the nice command starts a process with the default nice value of 10.

nice -n 15 command &
renice -n 19 1234

Summary

A relative priority is assigned to a process to determine its CPU access. This priority is called the nice value of a process. The nice command assigns a priority to a process when it starts. The renice command modifies the priority of a running process.

Command References:

A signal is a software interrupt that reports events to an executing program. The kill , pkill and killall commands use signals to control processes. Also see uptime, lscpu and top, nice, renice and top.