Linux Help:Tip of the Day:My system is slow because of some big process (so I want to change its priority)

From TLUG Wiki

Jump to: navigation, search

From the TLUG mailing list
Quoth Josh Glover:


If you started some big hungry process (e.g. backing up a DVD) and now your system is not responsive enough for your Firefox / XEmacs / GQview / jUploadr workload, simply drop (well, "raise", in UNIX Land) the priority of the CPU hogging process:

  1. Identify the process ID of the hog:
    ps -u "${USER}" -O pcpu --sort pcpu | sed -e 1d | sort -nr -k 2 | head
    See #Identifying the Process for an explanation
  2. Change the priority of the process:
    PID=<pid> # where <pid> is process ID from the previous step
NICENESS=10 # or change 10 to any integer between 1 and 20, inclusive
renice +${NICENESS} ${PID}

Your system should get noticeably more responsive!

See man 8 renice for more details.


Identifying the Process

Here is a breakdown of the pipeline (Wikipedia) we used above:

  1. ps -u "${USER}" -O pcpu --sort pcpu
    (man 1 ps); show all processes for the current user, adding CPU usage (percentage) to the default display columns, sorting by CPU usage (percentage)
  2. sed -e 1d
    (man 1 sed); delete the first line (i.e. ps's header)
  3. sort -nr -k 2
    (man 1 sort); sort numerically in reverse (i.e. descending order) on column 2
  4. head
    (man 1 head); display the first few lines only
Personal tools