巧用 ps 找 CPU 用量最高跟記憶體用量最高的程序

因為還蠻常用的,就紀錄起來,之後就直接複製了。

ps aux --sort -%cpu | head -n 10
ps aux --sort -%mem | head -n 10
ps -eo pid,ppid,cmd,comm,%mem,%cpu --sort=-%mem | head -10

這邊要注意的是,MacOS 的 ps 跟 Linux 的 ps 不一樣,沒有 –sort 這個參數,MacOS 是用 -r 跟 -m 來做排序。

ps aux -r | head -n 10
ps aux -m | head -n 10

參考資料

從 proc 找 IP

一般來說,在安裝完 Linux 都會有 ifconfig 或是 ip 指令可以查詢主機的 IP。在容器環境裡,會因為要節省容器映像的空間,就不裝這些指令了。那要怎麼查 IP 呢? 可以從 /proc 來查詢。

cat /proc/net/fib_trie
cat /proc/net/fib_trie | grep "|--"   | egrep -v "0.0.0.0| 127."

就這樣,蠻簡單的。

參考資料