New FAMILUG

The PyMiers

Thursday 16 April 2015

[CLI] top 10 process dùng nhiều tài nguyên nhất, tmux tip

Không có gì màu mè cả, đơn giản chỉ cần dùng top và cho sắp xếp theo một cột nào đó là xong, nhưng bài này dùng ps và sort.

1. top 5 dùng nhiều CPU nhất:
$ ps xau | head -n1; ps xau | sort -nrk3 | head -n5
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     28368  3.8  4.1 357208 41932 pts/4    Sl+  14:02   0:23 /usr/bin/python /usr/bin/salt-master -ldebug
root     28744  1.8  5.4 523132 55292 pts/5    Sl+  14:07   0:05 /usr/bin/python /usr/bin/salt-run state.orch orchestration.es -ldebug
root     28356  1.2  2.6 298472 27028 pts/4    Sl+  14:02   0:07 /usr/bin/python /usr/bin/salt-master -ldebug
root     28801  1.0  3.3 372236 34168 ?        S    14:07   0:02 /usr/bin/python /usr/bin/salt-cloud --profile ci-minion es7
root     28629  0.8  3.3 372980 34476 ?        S    14:03   0:04 /usr/bin/python /usr/bin/salt-cloud --profile ci-minion es7
ps xau để hiển thị các process đang chạy, head -n1 sẽ lấy dòng title để cho dễ nhìn,
sort -nrk3 để sắp xếp theo kiểu số học (-n) từ lớn xuống nhỏ (-r) theo cột thứ 3 (-k cột %CPU)
head -n5 để lấy 5 kết quả đầu tiên.


2. top 3 process dùng nhiều RAM nhất (tính bằng RSS)
tức cột thứ 6:

$ ps xau | sort -nrk6 |head -n3
root     28378  0.1  4.6 836268 47652 pts/4    Sl+  14:02   0:01 /usr/bin/python /usr/bin/salt-master -ldebug
root     28381  0.1  4.6 836776 47644 pts/4    Sl+  14:02   0:00 /usr/bin/python /usr/bin/salt-master -ldebug
root     21106  0.0  4.1 501348 42396 ?        Ssl  11:09   0:07 /usr/bin/python /usr/bin/salt-minion

3. tmux tip
- Để sử dụng tmux với VI binding, lúc bật tmux, gõ:
$ EDITOR=vi tmux
- Hoặc nếu đã trong 1 tmux session thì gõ:
Ctrl-b : 
rồi gõ
 set-window-option -g mode-keys vi
hoặc thêm dòng đó vào file tmuxrc

Hết.

No comments:

Post a Comment