System Priorities

Priorities of programs are something to be aware of.

The first thing to do is to get to know your processes. The ps command lists out the processes you have running on the system. By using ps -l, an extended listing of your processes is provided. The fields of the most interest to this topic are the PID, NI, and COMMAND fields. The COMMAND field lists the name of the command that started your process. So, if you're looking for your runaway c++ program, a.out is the one you want. The PID field lists each process's Process IDentifier. You're going to need to know that identifier number for most of the commands which affect processes. Finally, the NIce field lists a number between 0 and 39 (-20 and 19 on some other systems) which tells how high of a priority the process has (the smaller numbers being higher priority.) Processes you start typically have a default NI value of 20, which is the highest you can use. The values 0 to 19 are reserved for system administration.

Now, if you've got a program that has frozen on you and you can't get it to quit using control-c or if the process is running and you just can't find a way to stop it through normal channels, there's the kill command. The kill command takes a number 1 to 9 and a PID. The first number, denotes how badly you want to kill the process. 1 indicates a hang-up and will allow the process to auto save and shutdown regularly if possible. Therefore, this is the preferred way to kill a process if necessary. A 9 will pretty much kill any process in it's tracks, and the numbers in between are a scale between these two extremes. For example, if you want to kill your emacs session with PID: 627, you should try kill -1 627.

Now, to make your process run with a different priority than normal, there are the nice and renice commands. For a process already running, the renice value will change the priority. For example, to change the priority of a running process from the standard 20 to 25 (so that it runs after the other processes in the queue,) first use ps to get the PID. Let's say the PID is 941. Then, type renice -n 5 -p 941 Alternatively, if you know a process should run at a lower priority when you start it, the nice command will start it off with a lower priority. The easiest way is to use the default nice value of 4 lower than your terminal NIce value. For example, nice a.out should start a.out at a NIce value of 24 if you haven't changed your terminal NIce value.

So, now you know all about how to deal with processes and their priorities on our system. For more information, check the man pages (you can run man through the emacs Help menu, off this web page (ps, kill, nice, renice) or from a terminal with the man command.)