procps
出自DebianWiki
目錄 |
[編輯] procps
這裡介紹 DebianPackages:procps 的相關指令。DebianPackages:procps 可用來讀取 /proc 檔案系統,也就是讀取目前系統執行的程式狀態。計畫首頁 http://procps.sourceforge.net/
[編輯] ps
檢示目前正在執行中的 process:ps,可和 grep 指令搭配使用。
- ps 參數前面不用加 『-』。
- -a : 顯示在所有終端機下所執行的程序。
- a : 顯示在現在的終端機下所執行的所有程序。
- -A : 顯示所有的程序。包含所有的服務。
- -f : 顯示 UID、PPIP、C、STIME 欄位。
- -H : 顯示樹狀結構,表達程序間的相互關係。
- S : 列出程序時,包含『已死亡』 的子程序資訊。
- u : 以使用者程序為主的格示來顯示。
- v : 以虛擬記憶體的格式來顯示。
- V : 顯示版本資訊。
- x : 顯示所有的程序,不以終端機來分別。
檢示正在背景中執行的程式:
user@debian:~$ ps -aux
[編輯] kill
刪除在背景中執行的程式:
$ kill % JobID(使用 jobs 來取得 JobID)
$ /bin/kill[#]ProcessID(使用 ps 來取得 ProcessID)
$ /bin/kill -HUP/-1:重新啟動某個 process。
如果無法刪除,試試
/bin/kill 15[#]ProcessID
如果還是無法刪除,試試
/bin/kill 9[#]ProcessID。
[編輯] nice
以 nice 設定 Precess 的優先順序:(可用 ps -l 中的 NI 欄位來檢視 Process 的 優先順序。)-19 為最高而 20 為最低。
nice Command &(將程式放到背景執行,同時指定優先順序為 10。) nice # Command &(將程式放到背景執行,同時指定優先順序為#。)
改變 Precess 的優先順序:
renice # [#]ProcessID(將指定的背景中執行程式的優先順序設定為 #。) renice -u UserName # [#]ProcessID(將指定的使用者的背景中執行程式的優先順序全部 設定為#。)
[編輯] top 指令介紹
top 用於即時檢示目前的系統使用概況。會顯示所有執行中的程序(task)狀態,如ZombieProcess等資訊。預設以 CPU 使用率排序,可於介面按 <q> 離開。
按 <M> 會以 Memory 使用率排序。 按 <T> 會以已執行時間排序。 按 <C> 可以檢視命令列的參數。 按 <p> 可以檢視命令列的參數。 按 <u> 可以檢視特定的使用者。 按 <p> 可以直接刪除某一特定的 Process。 按 <s> 來指定更新的頻率。
[編輯] vmstat
vmstat 可用來紀錄 processes, memory, paging, block IO, traps, 與 cpu activity。
例如
$ vmstat 1 # 1 是更新速度,單位為秒 procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 1 0 549368 13316 102388 91992 12 6 9 8 2 12 72 3 25 0 2 0 549368 13316 102388 91992 0 0 0 0 156 1516 98 2 0 0 2 0 549368 13312 102388 91992 0 0 0 0 125 534 99 1 0 0 ....第一列與第二列所代表是執行程式的資訊,接下來的是記憶體、swap、io、systm 與 cpu。
Procs
r: The number of processes waiting for run time.
b: The number of processes in uninterruptible sleep.
Memory
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.
[編輯] watch
可以使用 watch 命令來反覆執行特定命令。如:watch -n 60 who;其中 -n 指更新的頻率。
![[Main Page]](/upload/4/49/Debian_taiwan_out.png)