當前位置:
首頁 >
linux基础命令 - ps
發布時間:2023/12/20
39
豆豆
生活随笔
收集整理的這篇文章主要介紹了
linux基础命令 - ps
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡單幫助
ps --help ps --help all man psps - report a snapshot of the current processes. ps [options]ps 給出的是系統當前運行進程的一個快照,要想實時看到系統中進程的變化,可以用 top 命令ps的參數比較多,并且有時需要區分格式,具體情況可通過實際測試觀察到This version of ps accepts several kinds of options: 1 UNIX options, which may be grouped and must be preceded by a dash. 2 BSD options, which may be grouped and must not be used with a dash. 3 GNU long options, which are preceded by two dashes.使用示例 [root@xingyongsheng ~]# ps aux | head -5 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 191132 3692 ? Ss Feb14 0:45 /usr/lib/systemd/systemd --system --deserialize 20 root 2 0.0 0.0 0 0 ? S Feb14 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Feb14 29:32 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< Feb14 0:00 [kworker/0:0H]ps -ef: 用戶進程不帶中括號, 內核進程帶中括號 用戶進程祖先(1號進程, systemd); 內核進程祖先(2號進程, kthreadd) tty ? 一般表示后臺服務常見操作組合
[root@xingyongsheng ~]# ps | head -3PID TTY TIME CMD9623 pts/1 00:00:00 bash 32505 pts/1 00:00:00 bash PID 進程號,比如用 "kill 進程號" ,結束該進程 TTY 進程所屬的終端控制臺 TIME 進程所使用的CPU時間 CMD 正在執行的命令[root@xingyongsheng ~]# ps -ef | head -3 UID PID PPID C STIME TTY TIME CMD root 1 0 0 Feb14 ? 00:00:45 /usr/lib/systemd/systemd --system --deserialize 20 root 2 0 0 Feb14 ? 00:00:00 [kthreadd] UID 執行該進程的用戶 PID 進程號 PPID 進程的父進程號 C CPU使用的資源百分比 STIME 進程開始時間 TTY 進程在哪個終端窗口里執行,若與終端無關,則顯示 "?" ,tty1-tty6 ,是本機上面的登陸者,pts/0 pts/1 ... 這樣的屬于網絡連接的進程(多開幾個終端窗口用w命令可看到) TIME 進程所使用的總CPU時間 CMD 正在執行的命令[root@xingyongsheng ~]# ps aux | head -5 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 191132 3692 ? Ss Feb14 0:46 /usr/lib/systemd/systemd --system --deserialize 20 root 2 0.0 0.0 0 0 ? S Feb14 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Feb14 29:32 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< Feb14 0:00 [kworker/0:0H] USER 哪個用戶執行的這個進程 PID 進程號 %CPU 進程使用掉的CPU資源百分比 %MEM 進程所占用的物理內存百分比 VSZ 該進程使用掉的虛擬內存,單位KB RSS 該進程使用的固定內存,單位KB TTY 同上 STAT 該進程目前的狀態PROCESS STATE CODESHere 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 by job control signalt stopped by debugger during the tracingW 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 parentFor 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 leaderl is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)+ is in the foreground process group START 該進程被觸發啟動的時間 TIME 該進程實際使用的CPU時間 COMMAND 該進程的實際命令實際場景舉例
查找某個進程是否運行 ? ps -ef | grep ssh OR ps aux | grep ssh查看系統里一共有多少進程 ? ps -ef | wc -l OR ps aux | wc -l查看系統里一共有多少線程 ? ps xH | wc -l OR ps -e -f H | wc -l OR找出系統中使用內存最大的進程 ps aux | sort -rnk4 | head找出系統中使用CPU最大的進程 ps aux | sort -rnk3 | head統計某個相關進程CPU使用累加和 ps aux | fgrep "php-fpm: pool api.sxxx.com.cn" | awk '{ sum += $3 }; END { print sum }'樹形顯示進程
root@localhost:/tmp # ps -ef f | egrep "nginx|PID" UID PID PPID C STIME TTY STAT TIME CMD root 22664 1 0 Feb11 ? Ss 1:37 nginx: master process /usr/local/bin/tengine -c /usr/local/etc/tengine.conf www 10516 22664 0 Jun28 ? S 84:25 \_ nginx: worker process www 10520 22664 0 Jun28 ? S 84:40 \_ nginx: worker process www 10526 22664 0 Jun28 ? S 84:00 \_ nginx: worker process www 10528 22664 0 Jun28 ? S 84:14 \_ nginx: worker process www 10531 22664 0 Jun28 ? S 84:17 \_ nginx: worker process www 10535 22664 0 Jun28 ? S 84:37 \_ nginx: worker process www 10539 22664 0 Jun28 ? S 84:44 \_ nginx: worker process www 10543 22664 0 Jun28 ? S 84:15 \_ nginx: worker process www 10547 22664 0 Jun28 ? S 84:28 \_ nginx: worker process www 10551 22664 0 Jun28 ? S 84:53 \_ nginx: worker process www 10552 22664 0 Jun28 ? S 84:19 \_ nginx: worker process www 10554 22664 0 Jun28 ? S 83:46 \_ nginx: worker process www 10556 22664 0 Jun28 ? S 84:19 \_ nginx: worker process www 10557 22664 0 Jun28 ? S 84:35 \_ nginx: worker process www 10560 22664 0 Jun28 ? S 85:30 \_ nginx: worker process www 10564 22664 0 Jun28 ? S 85:19 \_ nginx: worker process www 10570 22664 0 Jun28 ? S 84:51 \_ nginx: worker process www 10575 22664 0 Jun28 ? S 84:24 \_ nginx: worker process www 10580 22664 0 Jun28 ? S 84:50 \_ nginx: worker process www 10581 22664 0 Jun28 ? S 85:15 \_ nginx: worker process www 10582 22664 0 Jun28 ? S 84:47 \_ nginx: worker process www 10583 22664 0 Jun28 ? S 85:58 \_ nginx: worker process www 10584 22664 0 Jun28 ? S 84:49 \_ nginx: worker process www 10585 22664 0 Jun28 ? S 84:28 \_ nginx: worker process www 10586 22664 0 Jun28 ? S 0:40 \_ nginx: cache manager process root 21154 19359 0 16:42 pts/0 S+ 0:00 | \_ grep -E --color=auto nginx|PID總結
以上是生活随笔為你收集整理的linux基础命令 - ps的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言猜数字游戏及关机程序
- 下一篇: linux操作系统实验教程费翔林,实验一