Saturday, June 09, 2012

Linux 14 - Process Priorites

  • niceness explained
  • ps
  • pstree
  • htop
  • nice
  • renice
nice
Execute programs at a specified priority level

Untitled
This allows you to control which processes the kernel should favor when dividing processor time among running programs. Processes with the lowest nice number are executed with the highest priority and vice versa.
On most systems, priority levels for normal users range from 0 to 19, with 0 being the highest priority and 19 being the lowest priority. The root user can create processes with a range of -20 (highest) to 19 (lowest).
ps
Display running processes.
The ps command displays running process on the system. Executing the ps command with no options will display all processes owned by the current user
For a complete listing of all the processes, use the -e option
$ ps -e
  PID TTY          TIME CMD
    1 ?        00:00:02 init
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 migration/0
    4 ?        00:00:00 ksoftirqd/0
    5 ?        00:00:00 watchdog/0
    6 ?        00:00:00 migration/1
    7 ?        00:00:00 ksoftirqd/1
    8 ?        00:00:00 watchdog/1
    9 ?        00:00:00 migration/2
   10 ?        00:00:00 ksoftirqd/2
The -ef flags can be used to display very detailed information about the processes on the system.

$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 15:39 ?        00:00:02 init [2]  
root         2     0  0 15:39 ?        00:00:00 [kthreadd]
root         3     2  0 15:39 ?        00:00:00 [migration/0]
root         4     2  0 15:39 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 15:39 ?        00:00:00 [watchdog/0]
root         6     2  0 15:39 ?        00:00:00 [migration/1]
root         7     2  0 15:39 ?        00:00:00 [ksoftirqd/1]
root         8     2  0 15:39 ?        00:00:00 [watchdog/1]
root         9     2  0 15:39 ?        00:00:00 [migration/2]
root        10     2  0 15:39 ?        00:00:00 [ksoftirqd/2]
The alx is the BSD style “all processes, long format”
$ ps alx 
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0     1     0  20   0   8356   808 ?      Ss   ?          0:02 init [2]  
1     0     2     0  20   0      0     0 ?      S    ?          0:00 [kthreadd]
[…]
5 0 14 2 -100 - 0 0 ? S ? 0:00 [watchdog/3] 1 0 15 2 20 0 0 0 ? S ? 0:00 [events/0] 1 0 16 2 20 0 0 0 ? S ? 0:00 [events/1] 1 0 17 2 20 0 0 0 ? S ? 0:00 [events/2] 1 0 18 2 20 0 0 0 ? S ? 0:00 [events/3] 1 0 19 2 20 0 0 0 ? S ? 0:00 [cpuset] 1 0 20 2 20 0 0 0 ? S ? 0:00 [khelper] 1 0 21 2 20 0 0 0 ? S ? 0:00 [netns] 1 0 22 2 20 0 0 0 ? S ? 0:00 [async/mgr] 1 0 23 2 20 0 0 0 ? S ? 0:00 [pm] 1 0 30 2 20 0 0 0 ? S ? 0:00 [kblockd/0] 1 0 31 2 20 0 0 0 ? S ? 0:00 [kblockd/1] 1 0 32 2 20 0 0 0 ? S ? 0:00 [kblockd/2] 1 0 33 2 20 0 0 0 ? S ? 0:00 [kblockd/3] 1 0 34 2 20 0 0 0 ? S ? 0:00 [kacpid]

pstree
– very visual display of all the processes that are running in a tree like structure

Debian 6 64-bit-2012-03-13-18-32-43
htop - interactie process viewer (ala Windows's Task Manager)

Debian 6 64-bit-2012-03-13-18-33-43
nice - run a program's with a specific priority
- default nice level is 10
- nice -n ## (-xx) sleep 1000

renice - change the priority of a running program


No comments:

Post a Comment