---
tags: Unix-like
---
# Process Status
## `ps`
將某個時間點的程序運作情況擷取下來。
落落長,所以通常搭配 `more` 或 `grep` 來使用:
```shell
$ ps aux | more
$ ps aux | grep something
```
## 參數
- `aux`:觀察系統所有的程序資料
- `o` :指定顯示特定欄位,`$ ps o pid,command`
## 欄位說明
| Column | Description |
|:------:|-------------|
| USER | 擁有者 |
| PID | Process ID |
| %CPU | CPU 使用率 |
| %MEM | 記憶體使用率 |
| VSZ | 虛擬記憶體使用量,以 KB 為單位 |
| RSS | 固定占用的記憶體,以 KB 為單位 |
| TTY | 終端機編號,系統服務均無終端機,TTY 欄為 `?` |
| STAT | 目前狀態。 |
| | R(Running):該程式正在運作中 |
| | S(Sleep):該程式目前正在睡眠狀態(idle),但可以被喚醒(signal) |
| | D:不可被喚醒的睡眠狀態,通常這支程式可能在等待 I/O 的情況,如:列印 |
| | T(sTop):停止狀態,可能是在工作控制(背景暫停)或除錯(traced)狀態 |
| | Z(Zombie):僵屍狀態,程序已經終止但卻無法被移除至記憶體外 |
| START | 啟動日期 |
| TIME | 實際使用 CPU 時間 |
| COMMAND | 該行程指令 |
| NI | 優先權 Nice Value,以 -20 至 19 表示,數字越小表示該行程擁有的優先權越高 |
| PRI | 優先權序值 Priority,越小則越能優先被系統執行,系統會先為每個行程產生一個動態 PRI 值,加上 nice 後成為最終的 Priority |
> Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process:
>
> ```
> D Uninterruptible sleep (usually IO)
> R Running or runnable (on run queue)
> S Interruptible sleep (waiting for an event to complete)
> T Stopped, either by a job control signal or because it is being traced.
> W paging (not valid since the 2.6.xx kernel)
> X dead (should never be seen)
> Z Defunct ("zombie") process, terminated but not reaped by its parent.
> ```
>
> For BSD formats and when the stat keyword is used, additional characters may be displayed:
>
> ```
> < high-priority (not nice to other users)
> N low-priority (nice to other users)
> L has pages locked into memory (for real-time and custom IO)
> s is a session leader
> l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
> + is in the foreground process group
> ```
>
> [name=[`ps` / man page](http://man7.org/linux/man-pages/man1/ps.1.html)]