Server Process Priorities
Especially for Linux (Ubuntu)
PS Usage and Examples
ps creates a list of all running processes.
Look under the NI list for process niceness (priority). Priorities run from -20 to 20 (highest priority to lowest).
Nice Usage and Examples
Nice runs a command (creates a process) with a set priority.
sudo nice -priority command
Setting a -20 priority is –20, while a 20 priority is -20
Because it may not be possible to separate processes into users, nice can be used with cron to call services with specific priorities. For example, a virus scanner should not take priority over apache on a webserver.
sudo crontab -e
Prefix cron commands with
nice -priority. For example, Sophos AV:
00 11,16 * * * nice -20 savscan -all -pua -suspicious --examine-x-bit -archive /
renice – alter priority of running processes
ionice – set or retrieve the I/O priority for a given pid or execute a new task with a given I/O priority.
iostat – report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions.
ulimit – provide control over the resources available to processes started by the shell on systems that allow such control.
chrt – set or retrieve real-time scheduling parameters for a given pid or execute a new task under given scheduling parameters.
taskset – set or retrieve task CPU affinity for a given pid or execute a new task under a given affinity mask.
Default Niceness for Specific Users
For servers, it may be a good idea to separate processes (mysql, www-data, etc) for both security and process niceness. For example, the web server should never be run as root.
To set niceness for users permanently, run this command and input the desired values:
sudo nano /etc/security/limits.conf
Syntax: [username] [hard|soft] priority [nice value]
backupuser hard priority 1