Linux進程管理之ps的使用

?

?

?

?

?

主題Linux進程管理之ps工具的使用

?

?

?

一ps工具的介紹

?

?

ps: process state? 進程狀態
ps - report a snapshot of the current processes
Linux系統各進程的相關信息均保存在/proc/PID目錄下的各文件中

?

?

默認顯示的內容很少

[root@centos65 ~]# psPID TTY          TIME CMD2018 pts/0    00:00:00 bash 2656 pts/0 00:00:00 ps

?

?

?

?

[root@centos72 ~]# psPID TTY          TIME CMD1928 pts/0    00:00:01 bash 101855 pts/0 00:00:00 ps

?

?

?

?

?

?

顯示當前終端的進程

[root@centos65 ~]# tty
/dev/pts/0

?

?

?

?

?

[root@centos65 ~]# sleep   10  &
[1] 2678 [root@centos65 ~]# ps PID TTY TIME CMD 2018 pts/0 00:00:00 bash 2678 pts/0 00:00:00 sleep 2679 pts/0 00:00:00 ps

?

?

?

?

?

?

?

?

二ps支持的選項

?

?

ps [OPTION]...
支持三種選項:
UNIX選項 如-A
BSD選項? 如a
GNU選項 如--help
選項:默認顯示當前終端中的進程
? a 選項包括所有終端中的進程
? x 選項包括不鏈接終端的進程
? u 選項顯示進程所有者的信息
? f 選項顯示進程樹,相當于 --forest
? k| --sort 屬性 對屬性 排序,屬性前加- 表示倒序
? o 屬性… 選項顯示定制的信息 pid、cmd、%cpu、%mem
? L 顯示支持的屬性列表

?

?

?

?

?

?

?

(一)BSD風格的選項(最常用)

?

(1)a顯示所有終端中的進程

?

PID是進程的標識號。
TTY是進程所屬的終端控制臺。
TIME列是進程所使用的總的CPU時間。
CMD列是正在執行的命令行。

[root@centos65 ~]# ps aPID TTY      STAT   TIME COMMAND1866 tty1     Ss+    0:00 /sbin/mingetty /dev/tty1 1868 tty2 Ss+ 0:00 /sbin/mingetty /dev/tty2 1871 tty3 Ss+ 0:00 /sbin/mingetty /dev/tty3 1873 tty4 Ss+ 0:00 /sbin/mingetty /dev/tty4 1875 tty5 Ss+ 0:00 /sbin/mingetty /dev/tty5 1877 tty6 Ss+ 0:00 /sbin/mingetty /dev/tty6 2018 pts/0 Ss 0:00 -bash 2455 pts/1 Ss 0:00 -bash 2496 pts/1 S 0:00 su - wang 2497 pts/1 S+ 0:00 -bash 2752 pts/0 R+ 0:00 ps a

?

?

?

?

[root@centos65 ~]# su - wang
[wang@centos65 ~]$ ls
[wang@centos65 ~]$ vim  /etc/fstab 
[wang@centos65 ~]$ tty /dev/pts/1

?

?

?

?

?

?

?

(2)x顯示和終端無關的進程

?

不需要用戶賬號登錄就可以運行,機器啟動就運行起來了

[root@centos72 ~]# ps ax  | headPID TTY      STAT   TIME COMMAND1 ?        Ss     0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 2 ? S 0:00 [kthreadd] 3 ? S 0:00 [ksoftirqd/0] 5 ? S< 0:00 [kworker/0:0H] 7 ? S 0:00 [migration/0] 8 ? S 0:00 [rcu_bh] 9 ? R 0:00 [rcu_sched] 10 ? S< 0:00 [lru-add-drain] 11 ? S 0:00 [watchdog/0] [root@centos72 ~]# ps ax | tail 882 ? Ssl 0:00 /usr/sbin/rsyslogd -n 906 ? Ss 0:00 sshd: root@pts/0 967 ? Ss 0:00 /usr/libexec/postfix/master -w 968 ? S 0:00 pickup -l -t unix -u 969 ? S 0:00 qmgr -l -t unix -u 1142 pts/0 Ss 0:00 -bash 1179 ? S 0:00 [kworker/0:0] 1191 ? S 0:00 [kworker/0:1] 1195 pts/0 R+ 0:00 ps ax 1196 pts/0 D+ 0:00 -bash

?

?

?

?

?

?

?

?

?

?

(3)顯示所有和終端有關的進程用戶信息

?


USER:該進程屬于的用戶。


PID:該進程的進程號。


%CPU:該進程使用掉的CPU資源百分比,CPU利用率

?

%MEM:該進程所占用的物理內存百分比,內存利用率


VSZ:該進程使用掉的虛擬內存量(單位為Kbytes)

?

VSZ虛擬內存占用(操作系統給應用程序的內存大小,包括物理內存和swap內存)

 vsz         VSZ       virtual memory size of the process in KiB (1024-byte units). 
進程的虛擬內存大小為KiB(1024字節單位)。Device  mappings are currently excluded; this is subject to change. (alias  vsize).
目前不包括設備映射;這一點可能會改變。(別名vsize)。

?

?

?

?

?

RSS:Resident Set Size,該進程占用的固定的內存量(單位為Kbytes)。

?

RSS真正的物理內存


TTY:該進程是在哪個終端機上面運作的,若與終端機無關,則顯示“?”,

?

另外,tty1-tty6是本機上面的登入者進程,若為pts/0等,則表示為由網絡連接進主機的進程。


STAT:該進程目前的狀態,主要的狀態:


R:正在運行,或者是可以運行。


S:正在中斷睡眠中,可以由某些信號(signal)喚醒。


D:不可中斷睡眠。


T:正在偵測或者是停止了。


Z:已經終止,但是其父進程無法正常終止它,從而變成zombic(僵尸)進程的狀態。


+:前臺進程。


1:多線程進程。


N:低優先級進程。


<:高優先級進程。


s:進程領導者。


L:已將頁面鎖定到內存中。


START:該進程被觸發啟動的時間。


TIME:該進程實際使用CPU運作的時間。也就是TIME時間片的累計值


COMMAND:該進程的實際命令。

?

?

?

[root@centos72 ~]# ps au
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root        540  0.0  0.0 110088 856 tty1 Ss+ Jul08 0:00 /sbin/agetty --noclear tty1 linux root 1928 0.0 0.2 116092 2944 pts/0 Ss Jul09 0:01 -bash root 5073 0.0 0.1 155324 1868 pts/0 R+ 12:13 0:00 ps au root 103122 0.0 0.2 115832 2464 pts/1 Ss+ 01:00 0:00 -bash

?

?

?

?

?

?

?

?

(4)顯示所有進程用戶信息

?

組合選項使用最多的,因為顯示的信息很詳細

?

[root@centos72 ~]# ps axu  |  tail
root        882  0.0  0.8 214424 8664 ? Ssl 16:56 0:00 /usr/sbin/rsyslogd -n root 906 0.0 0.5 154588 5384 ? Ss 16:56 0:00 sshd: root@pts/0 root 967 0.0 0.2 89620 2080 ? Ss 16:56 0:00 /usr/libexec/postfix/master -w postfix 968 0.0 0.4 89724 4052 ? S 16:56 0:00 pickup -l -t unix -u postfix 969 0.0 0.4 89792 4080 ? S 16:56 0:00 qmgr -l -t unix -u root 1142 0.0 0.2 115968 2692 pts/0 Ss 16:56 0:00 -bash root 1179 0.0 0.0 0 0 ? S 17:01 0:00 [kworker/0:0] root 1191 0.0 0.0 0 0 ? S 17:06 0:00 [kworker/0:1] root 1197 0.0 0.1 155324 1860 pts/0 R+ 17:08 0:00 ps axu root 1198 0.0 0.0 107984 652 pts/0 R+ 17:08 0:00 tail [root@centos72 ~]# ps axu | head USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.6 127780 6436 ? Ss 16:55 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 2 0.0 0.0 0 0 ? S 16:55 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 16:55 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 16:55 0:00 [kworker/0:0H] root 7 0.0 0.0 0 0 ? S 16:55 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 16:55 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? R 16:55 0:00 [rcu_sched] root 10 0.0 0.0 0 0 ? S< 16:55 0:00 [lru-add-drain] root 11 0.0 0.0 0 0 ? S 16:55 0:00 [watchdog/0]

?

?

?

?

?

?

?

(5)f 選項顯示進程樹,相當于 --forest

[root@centos72 ~]# ps   auxf  | head
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          2  0.0 0.0 0 0 ? S Jul08 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Jul08 0:01 \_ [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< Jul08 0:00 \_ [kworker/0:0H] root 7 0.0 0.0 0 0 ? S Jul08 0:00 \_ [migration/0] root 8 0.0 0.0 0 0 ? S Jul08 0:00 \_ [rcu_bh] root 9 0.0 0.0 0 0 ? R Jul08 0:09 \_ [rcu_sched] root 10 0.0 0.0 0 0 ? S< Jul08 0:00 \_ [lru-add-drain] root 11 0.0 0.0 0 0 ? S Jul08 0:02 \_ [watchdog/0] root 13 0.0 0.0 0 0 ? S Jul08 0:00 \_ [kdevtmpfs]

?

?

?

?

?

?

顯示了進程的父子關系

進程必須放到樹上的某個分支

[root@centos65 ~]# ps  auxf  | grep   apache
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 2950 0.0 0.0 103324 836 pts/0 S+ 15:00 0:00 | \_ grep --color=auto apache apache 2300 0.0 0.5 521880 5344 ? Sl 14:20 0:00 \_ /usr/sbin/httpd.worker apache 2301 0.0 0.5 521880 5336 ? Sl 14:20 0:00 \_ /usr/sbin/httpd.worker apache 2303 0.0 0.5 521880 5340 ? Sl 14:20 0:00 \_ /usr/sbin/httpd.worker 

?

?

?

?

?

[root@centos72 ~]# ps  auxf   |  grep  sshd
root        862  0.0  0.4 112796 4336 ? Ss Jul08 0:00 /usr/sbin/sshd -D root 1924 0.0 0.5 154872 5756 ? Ss Jul09 0:03 \_ sshd: root@pts/0 root 103114 0.0 0.5 154588 5388 ? Ss Jul14 0:00 \_ sshd: root@pts/1 root 86615 0.0 0.0 112704 972 pts/1 S+ 16:18 0:00 \_ grep --color=auto sshd

?

?

?

?

?

?

(6)o自定義輸出指定的字段

[root@centos65 ~]# ps axo   pid,cmd,%cpu k cmd  | headPID CMD                         %CPU1761 abrt-dump-oops -d /var/spoo  0.0 1751 /usr/sbin/abrtd 0.0 1379 /usr/sbin/acpid 0.0 37 [aio/0] 0.0 14 [async/mgr] 0.0 23 [ata_aux] 0.0 24 [ata_sff/0] 0.0 1808 /usr/sbin/atd 0.0 1203 auditd 0.0

?

?

?

?

?

打開另外一個終端

[root@centos72 ~]# id  wang
uid=1000(wang) gid=1000(wang) groups=1000(wang) [root@centos72 ~]# su - wang Last login: Thu May 9 16:22:21 CST 2019 on pts/1 [wang@centos72 ~]$ passwd Changing password for user wang. Changing password for wang. (current) UNIX password: 

?

?

?

?

uid,euid都表示有效用戶是root,真正的用戶是wang

因為這是因為普通用戶具有suid權限

[root@centos72 ~]#  ps  axo   pid,cmd,ni,%cpu,uid,euid,ruid  |  tail1252 [kworker/0:2]                 0 0.0 0 0 0 1269 [kworker/0:0] 0 0.0 0 0 0 1270 [kworker/1:0] 0 0.0 0 0 0 1273 [kworker/1:2] 0 0.0 0 0 0 1276 su - wang 0 0.0 0 0 0 1277 -bash 0 0.0 1000 1000 1000 1300 passwd 0 0.1 0 0 1000 1305 [kworker/0:1] 0 0.0 0 0 0 1308 ps axo pid,cmd,ni,%cpu,uid, 0 0.0 0 0 0 1309 tail 0 0.0 0 0 0

?

?

?

?

?

?

(7)k按照指定字段排序

按照內存排序,在6上不支持

如果使用圖形化界面,切換到命令行就會節約很大的內存

[root@centos65 ~]# ps axo   pid,cmd,%cpu,%mem k %mem  |  tail2300 /usr/sbin/httpd.worker       0.0  0.52301 /usr/sbin/httpd.worker 0.0 0.5 2303 /usr/sbin/httpd.worker 0.0 0.5 2451 sshd: root@pts/1 0.0 0.4 2455 -bash 0.0 0.4 2496 su - wang 0.0 0.1 2497 -bash 0.0 0.4 3156 sleep 60 0.0 0.0 3160 ps axo pid,cmd,%cpu,%mem k 0.0 0.1 3161 tail 0.0 0.0

?

?

?

?

?

[root@centos72 ~]#  ps axo   pid,cmd,%cpu,%mem k  %mem  |  tail1507 sshd: root@pts/0             0.0  0.5 1531 sshd: root@pts/1 0.0 0.5 766 /usr/sbin/rsyslogd -n 0.0 0.5 526 /usr/bin/VGAuthService -s 0.0 0.6 527 /usr/bin/vmtoolsd 0.0 0.6 372 /usr/lib/systemd/systemd-ud 0.0 0.6 1 /usr/lib/systemd/systemd -- 0.0 0.6 539 /usr/sbin/NetworkManager -- 0.0 0.9 541 /usr/lib/polkit-1/polkitd - 0.0 1.1 765 /usr/bin/python -Es /usr/sb 0.0 1.9

?

?

?

?

?

?

內存的使用情況:

[root@centos72 ~]# free  -htotal        used        free      shared  buff/cache   available
Mem:           974M         98M        716M        7.7M 159M 705M Swap: 2.0G 0B 2.0G

?

?

?

?

?

?

?

?

(8)L 顯示支持的屬性列表

?

?

顯示線程,可能包含LWP和NLWP列。

[root@centos72 ~]# ps  L | head
%cpu         %CPU    
%mem         %MEM    
_left        LLLLLLLL
_left2       L2L2L2L2
_right       RRRRRRRR
_right2      R2R2R2R2
_unlimited   U       
_unlimited2  U2      
alarm        ALARM   
args         COMMAND 
[root@centos72 ~]# ps  L | tail user USER userns USERNS util C utsns UTSNS uunit UUNIT vsize VSZ vsz VSZ wchan WCHAN wname WCHAN zone ZONE 

?

?

?

?

?

?

6和7版本的屬性數量不一樣

[root@centos65 ~]# ps  L | wc154     308    3388

?

?

[root@centos72 ~]# ps  L | wc169     338    3718

?

?

?

?

?

?

?

?

?

?

?

(二)UNIX風格的選項

?

?

-C cmdlist 指定命令,多個命令用,分隔
-L 顯示線程
-e: 顯示所有進程,相當于-A
-f: 顯示完整格式程序信息
-F: 顯示更完整格式的進程信息
-H: 以進程層級格式顯示進程相關信息
-u userlist 指定有效的用戶ID或名稱
-U userlist 指定真正的用戶ID或名稱
-g gid或groupname 指定有效的gid或組名稱
-G gid或groupname 指定真正的gid或組名稱
-p pid 顯示指pid的進程
--ppid pid 顯示屬于pid的子進程
-M 顯示SELinux信息,相當于Z

?

?

?

?

?

(1)-e: 顯示所有進程,相當于-A

?

此選項常用

[root@centos72 ~]# ps -e |  headPID TTY          TIME CMD1 ?        00:00:01 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:00 ksoftirqd/0 5 ? 00:00:00 kworker/0:0H 7 ? 00:00:00 migration/0 8 ? 00:00:00 rcu_bh 9 ? 00:00:00 rcu_sched 10 ? 00:00:00 lru-add-drain 11 ? 00:00:00 watchdog/0 [root@centos72 ~]# ps -e | tail 967 ? 00:00:00 master 968 ? 00:00:00 pickup 969 ? 00:00:00 qmgr 1142 pts/0 00:00:00 bash 1179 ? 00:00:00 kworker/0:0 1191 ? 00:00:00 kworker/0:1 1206 ? 00:00:00 kworker/0:2 1207 ? 00:00:00 kworker/0:3 1228 pts/0 00:00:00 ps 1229 pts/0 00:00:00 tail

?

?

?

?

?

?

(2)-f: 顯示完整格式程序信息

顯示的內容更多

[root@centos72 ~]# ps -f  
UID         PID   PPID  C STIME TTY          TIME CMD
root       1928   1924  0 Jul09 pts/0 00:00:01 -bash root 76668 1928 0 12:54 pts/0 00:00:00 ps -f

?

?

?

?

?

?

(3)-L 顯示線程

第4列是線程編號

[root@centos72 ~]# ps -LPID    LWP TTY          TIME CMD1142   1142 pts/0    00:00:00 bash 1240 1240 pts/0 00:00:00 ps

?

?

?

?

?

[root@centos72 ~]#  ps -Lef | grep  sshd
root        877      1    877 0 1 16:56 ? 00:00:00 /usr/sbin/sshd -D root 906 877 906 0 1 16:56 ? 00:00:00 sshd: root@pts/0 root 1238 1142 1238 0 1 17:21 pts/0 00:00:00 grep --color=auto sshd

?

?

?

?

?

?

?

?

(4)顯示指定用戶的進程信息

?

-u userlist 指定有效的用戶ID或名稱

[root@centos72 ~]# ps -u  root  | headPID TTY          TIME CMD1 ?        00:00:39 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:01 ksoftirqd/0 5 ? 00:00:00 kworker/0:0H 7 ? 00:00:00 migration/0 8 ? 00:00:00 rcu_bh 9 ? 00:00:09 rcu_sched 10 ? 00:00:00 lru-add-drain 11 ? 00:00:02 watchdog/0 [root@centos72 ~]# ps -u root | tail 1928 pts/0 00:00:01 bash 3264 ? 00:00:02 kworker/u256:2 86289 ? 00:00:00 kworker/0:0 86830 ? 00:00:00 kworker/u256:0 86866 ? 00:00:00 kworker/0:1 87108 ? 00:00:00 kworker/0:2 87219 pts/1 00:00:00 ps 87220 pts/1 00:00:00 bash 103114 ? 00:00:00 sshd 103122 pts/1 00:00:00 bash

?

?

?

?

?

?

(5)顯示進程的特定屬性

?

?默認按PID顯示的

[root@centos72 ~]# ps   -o   pid,cmd,%cpu  | headPID CMD                         %CPU1142 -bash                        0.0 1248 ps -o pid,cmd,%cpu 0.0 1249 head 0.0

?

?

?

?

?

?

?

?

(6)-C cmdlist 指定命令,多個命令用,分隔

?

[root@centos65 ~]# ps -C  vimPID TTY          TIME CMD3266 pts/1    00:00:00 vim

?

?

?

?

注意shebang機制一定要寫,否則看不到腳本在運行

查看每個終端的進程

[root@centos65 ~]# ll f1.sh 
-rwxr-xr-x. 1 root root 23 May  9 15:32 f1.sh [root@centos65 ~]# cat f1.sh #!/bin/bash sleep 60 [root@centos65 ~]# bash f1.sh 

?

?

?

?

[root@centos65 ~]# ps -C  f1.shPID TTY          TIME CMD
[root@centos65 ~]# ps -C  bashPID TTY          TIME CMD2018 pts/0 00:00:00 bash 2455 pts/1 00:00:00 bash 3521 pts/1 00:00:00 bash 

?

?

?

?

?

兩個bash,一個是登錄bash,一個是執行腳本的bash

[root@centos65 ~]# w15:40:11 up  1:27, 2 users, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.137.1 14:14 0.00s 0.30s 0.00s w root pts/1 192.168.137.1 14:24 44.00s 0.13s 0.00s bash f1.sh

?

?

?

?

sshd(1632)─┬─sshd(2014)───bash(2018)───pstree(3566)│            └─sshd(2451)───bash(2455)───bash(3554)───sleep(3555)

?

?

?

?

注意不同風格的選項可以混用,但是不是全部的,這樣就可以關注特定的屬性

[root@centos65 ~]# ps  -C  vim,init  o  pid,cmd,%memPID CMD                         %MEM1 /sbin/init                   0.13650 vim /etc/fstab 0.4

?

?

?

?

?

(7)-F: 顯示更完整格式的進程信息

?

PSR表示進程運行在那顆CPU上

[root@centos72 ~]# ps -F
UID         PID   PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
root       1142    906  0 28992 2692 0 16:56 pts/0 00:00:00 -bash root 1250 1142 0 38831 1844 0 17:42 pts/0 00:00:00 ps -F

?

?

?

?

?

?目前只有1顆CPU

?

?

?

?

?

?

?

如果有多顆CPU就會進行切換,因為進程是有時間片的

時間到了就會釋放CPU的內存空間

[root@centos65 ~]#  ps  -C  vim,init  o  pid,cmd,%mem,psrPID CMD                         %MEM PSR1 /sbin/init                   0.1   0 3650 vim /etc/fstab 0.4 0

?

?

?

?

?

開啟2個CPU,另外開啟4個終端

并且執行相同的命令

[root@centos65 ~]# dd  if=/dev/zero  of=/dev/null

?

?

?

?

?

?

?

?

?

[root@centos65 ~]# lscpu 
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2 On-line CPU(s) list: 0,1 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 2 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 142 Model name: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz Stepping: 9 CPU MHz: 2903.999 BogoMIPS: 5807.99 Hypervisor vendor: VMware Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 4096K NUMA node0 CPU(s): 0,1

?

?

?

?

?

?

[root@centos65 ~]#  ps  -C  vim,dd  o  pid,cmd,%mem,tty,psrPID CMD                         %MEM TT       PSR3853 dd if=/dev/zero of=/dev/nul 0.0 pts/1 1 3881 dd if=/dev/zero of=/dev/nul 0.0 pts/2 1 4059 dd if=/dev/zero of=/dev/nul 0.0 pts/3 0 4118 dd if=/dev/zero of=/dev/nul 0.0 pts/4 0

?

?

?

?

使用watch查看

[root@centos65 ~]# watch  -n0.1 ps  -C  vim,dd  o  pid,cmd,%mem,tty,psr

?

?

?

?

在6上沒有看到變化,在7上看看

開啟2個CPU,3個終端

?

?

?

?

?

?

?

[root@centos72 ~]# lscpu 
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2 On-line CPU(s) list: 0,1 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 2 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 142 Model name: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz Stepping: 9 CPU MHz: 2903.999 BogoMIPS: 5807.99 Hypervisor vendor: VMware Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 4096K NUMA node0 CPU(s): 0,1 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat

?

?

?

?

?

?

?可以很明顯的看到變化,說明和版本有關系

7這樣可以充分利用CPU資源。避免了一核有難七核圍觀的尷尬情況

[root@centos72 ~]#  ps  -C  vim,dd  o  pid,cmd,%mem,tty,psrPID CMD                         %MEM TT       PSR8323 dd if=/dev/zero of=/dev/nul 0.0 pts/1 0 8369 dd if=/dev/zero of=/dev/nul 0.0 pts/2 0 8485 dd if=/dev/zero of=/dev/nul 0.0 pts/3 1 [root@centos72 ~]# ps -C vim,dd o pid,cmd,%mem,tty,psr PID CMD %MEM TT PSR 8323 dd if=/dev/zero of=/dev/nul 0.0 pts/1 0 8369 dd if=/dev/zero of=/dev/nul 0.0 pts/2 1 8485 dd if=/dev/zero of=/dev/nul 0.0 pts/3 1

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

普通用戶wang執行passwd有suid權限,生效的是root

而發起這個進程的用戶是wang

[root@centos72 ~]# su  - wang
[wang@centos72 ~]$ ls
[wang@centos72 ~]$ pwd
/home/wang [wang@centos72 ~]$ passwd Changing password for user wang. Changing password for wang. (current) UNIX password: 

?

?

?

?

[root@centos72 ~]# ps  -u  wangPID TTY          TIME CMD9274 pts/1    00:00:00 bash [root@centos72 ~]# ps -U wang PID TTY TIME CMD 9274 pts/1 00:00:00 bash 9390 pts/1 00:00:00 passwd

?

?

?

?

當普通用戶運行具有suid權限的文件時候,身份就變成了這個文件的所有者

[root@centos72 ~]# which  passwd
/usr/bin/passwd
[root@centos72 ~]# ll  /usr/bin/passwd 
-rwsr-xr-x. 1 root root 27832 Jun 10 2014 /usr/bin/passwd [root@centos72 ~]# file /usr/bin/passwd /usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=1e5735bf7b317e60bcb907f1989951f6abd50e8d, stripped 

?

?

?

?

?

?

?

(8)-p pid 顯示指pid對應的進程

[root@centos72 ~]# ps -p  1PID TTY          TIME CMD1 ?        00:00:02 systemd

?

?

?

[root@centos65 ~]# ps -p  1PID TTY          TIME CMD1 ?        00:00:01 init

?

?

?

?

部分顯示進程信息

[root@centos65 ~]# ps -p  1  o  pid,%mem,cmdPID %MEM CMD1  0.1 /sbin/init

?

?

?

?

?

?

普通用戶執行了passwd

[root@centos65 ~]# su - wang
[wang@centos65 ~]$ ls
1.sh [wang@centos65 ~]$ vim /etc/fstab [wang@centos65 ~]$ passwd Changing password for user wang. Changing password for wang. (current) UNIX password: 

?

?

?

?

[root@centos65 ~]# ps -C passwd  o  pid,%mem,cmdPID %MEM CMD5229  0.1 passwd 

?

?

?

?

[root@centos72 ~]# su  - wang
[wang@centos72 ~]$ ls
[wang@centos72 ~]$ pwd
/home/wang [wang@centos72 ~]$ passwd Changing password for user wang. Changing password for wang. (current) UNIX password: 

?

?

?

[root@centos72 ~]# ps -C passwd  o  pid,%mem,cmdPID %MEM CMD9390  0.1 passwd

?

?

?

?

?

?

?

常用選項組合ps -ef

?

?

C表示CPU的利用率

[root@centos65 ~]# ps  -ef  | head
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 14:12 ? 00:00:01 /sbin/init root 2 0 0 14:12 ? 00:00:00 [kthreadd] root 3 2 0 14:12 ? 00:00:00 [migration/0] root 4 2 0 14:12 ? 00:00:00 [ksoftirqd/0] root 5 2 0 14:12 ? 00:00:00 [stopper/0] root 6 2 0 14:12 ? 00:00:00 [watchdog/0] root 7 2 0 14:12 ? 00:00:01 [events/0] root 8 2 0 14:12 ? 00:00:00 [events/0] root 9 2 0 14:12 ? 00:00:00 [events_long/0] 

?

?

?

?

?

顯示所有進程

[root@centos72 ~]# ps  -ax  | headPID TTY      STAT   TIME COMMAND1 ?        Ss     0:39 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 2 ? S 0:00 [kthreadd] 3 ? S 0:01 [ksoftirqd/0] 5 ? S< 0:00 [kworker/0:0H] 7 ? S 0:00 [migration/0] 8 ? S 0:00 [rcu_bh] 9 ? R 0:09 [rcu_sched] 10 ? S< 0:00 [lru-add-drain] 11 ? S 0:02 [watchdog/0] [root@centos72 ~]# ps -ax | tail 3264 ? S 0:02 [kworker/u256:2] 85397 ? S 0:00 pickup -l -t unix -u 86289 ? S 0:00 [kworker/0:0] 86830 ? S 0:00 [kworker/u256:0] 86866 ? S 0:00 [kworker/0:1] 87108 ? S 0:00 [kworker/0:2] 87347 pts/1 R+ 0:00 ps -ax 87348 pts/1 R+ 0:00 tail 103114 ? Ss 0:00 sshd: root@pts/1 103122 pts/1 Ss 0:00 -bash

?

?

?

?

[root@centos65 ~]# ps -axo   pid,cmd,%cpu  | head
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ PID CMD %CPU 1 /sbin/init 0.0 2 [kthreadd] 0.0 3 [migration/0] 0.0 4 [ksoftirqd/0] 0.0 5 [stopper/0] 0.0 6 [watchdog/0] 0.0 7 [events/0] 0.0 8 [events/0] 0.0 9 [events_long/0] 0.0

?

?

?

?

?

?

?

?

?

?

(三)GNU風格的選項

?

?

?

按照命令來排序

[root@centos65 ~]# ps -axo   pid,cmd,%cpu  --sort   cmd  | head
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ PID CMD %CPU 1761 abrt-dump-oops -d /var/spoo 0.0 1751 /usr/sbin/abrtd 0.0 1379 /usr/sbin/acpid 0.0 37 [aio/0] 0.0 14 [async/mgr] 0.0 23 [ata_aux] 0.0 24 [ata_sff/0] 0.0 1808 /usr/sbin/atd 0.0 1203 auditd 0.0

?

?

?

?

?

?

--ppid pid 顯示屬于pid的子進程

注意不會顯示線程

[root@centos72 ~]# pstree -p
systemd(1)─┬─NetworkManager(539)─┬─{NetworkManager}(570)│                     └─{NetworkManager}(572) ├─VGAuthService(526) ├─agetty(552) ├─auditd(501)───{auditd}(502) ├─crond(545) ├─dbus-daemon(529)───{dbus-daemon}(538) ├─httpd(2210)─┬─httpd(2212) │ ├─httpd(2213) │ ├─httpd(2214) │ ├─httpd(2215) │ └─httpd(2216) ├─master(849)─┬─pickup(6815) │ └─qmgr(851) ├─polkitd(541)─┬─{polkitd}(564) │ ├─{polkitd}(565) │ ├─{polkitd}(566) │ ├─{polkitd}(567) │ └─{polkitd}(568) ├─rsyslogd(766)─┬─{rsyslogd}(769) │ └─{rsyslogd}(770) ├─sshd(763)─┬─sshd(1507)───bash(1511) │ ├─sshd(1531)───bash(1535)───pstree(10043) │ ├─sshd(8337)───bash(8345)───dd(8369) │ └─sshd(8457)───bash(8465)───dd(8485) ├─systemd-journal(347) ├─systemd-logind(528) ├─systemd-udevd(372) ├─tuned(765)─┬─{tuned}(1006) │ ├─{tuned}(1007) │ ├─{tuned}(1008) │ └─{tuned}(1022) └─vmtoolsd(527)───{vmtoolsd}(553)

?

?

?

?

?

[root@centos72 ~]# ps --ppid  2210PID TTY          TIME CMD2212 ?        00:00:00 httpd 2213 ? 00:00:00 httpd 2214 ? 00:00:00 httpd 2215 ? 00:00:00 httpd 2216 ? 00:00:00 httpd

?

?

?

?

?

[root@centos65 ~]# pstree  
init─┬─abrt-dump-oops├─abrtd├─acpid├─atd├─auditd───{auditd}├─automount───4*[{automount}]├─crond├─dbus-daemon───{dbus-daemon}├─dnsmasq├─hald─┬─hald-runner─┬─hald-addon-acpi │ │ └─hald-addon-inpu │ └─{hald} ├─httpd.worker───3*[httpd.worker───26*[{httpd.worker}]] ├─ksmtuned───sleep ├─libvirtd───10*[{libvirtd}] ├─master─┬─pickup │ └─qmgr ├─6*[mingetty] ├─rpc.idmapd ├─rpc.mountd ├─rpc.rquotad ├─rpc.statd ├─rpcbind ├─rsyslogd───3*[{rsyslogd}] ├─sshd─┬─sshd───bash │ └─sshd───bash───pstree ├─udevd───2*[udevd] └─xinetd

?

?

?

?

[root@centos65 ~]# ps --ppid  2298PID TTY          TIME CMD2300 ?        00:00:00 httpd.worker 2301 ? 00:00:00 httpd.worker 2303 ? 00:00:00 httpd.worker

?

轉載于:https://www.cnblogs.com/wang618/p/11191017.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/248474.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/248474.shtml
英文地址,請注明出處:http://en.pswp.cn/news/248474.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

openstack Q版部署-----安裝報錯問題

1、實例開機提示找不到磁盤Booting from Hard Disk... GRUB. 開啟 CPU 虛擬化支持。 將計算節點 nova.conf 配置修改如下即可&#xff1a; [libvirt] cpu_mode none virt_type qemu重啟服務 systemctl restart libvirtd.service openstack-nova-compute.service 2、錯誤: 超過…

深入Vue原理_雙向數據綁定(視圖/數據)

歡迎各位小伙伴們&#xff01; 為大家推薦一款刷題神奇哦 點擊鏈接訪問牛客網 各大互聯網大廠面試真題。從基礎到入階乃至原理刨析類面試題 應有盡有&#xff0c;趕快來裝備自己吧&#xff01;助你面試穩操勝券&#xff0c;solo全場面試官 文章目錄數據的變化反應到視圖命令式操…

【BZOJ3894】文理分科

已經連續很久沒有當場想出來題了。。。。 $yyb$認為這是一道傻逼題&#xff0c;但是我并不這么認為。。。。 題面 https://www.lydsy.com/JudgeOnline/problem.php?id3894 題解 加點&#xff1a;三叉戟結構的小技巧。 假設割$S$表示不學文&#xff0c;割$T$表示不學理。 對于一…

CodeForces 1131G. Most Dangerous Shark

題目簡述&#xff1a;從左到右依次有$n \leq 10^7$個Domino骨牌&#xff0c;高度為$h_i$&#xff0c;手動推倒他的花費為$c_i$。每個骨牌之間的距離為$1$。一個骨牌可以被向左或者向右推倒。當第$i$個骨牌被推倒時&#xff0c;他會以相同方向推倒與其距離$<h_i$的所有骨牌。…

大廠直通車【C認證】踵磅來襲

歡迎各位小伙伴們&#xff01; 首先為大家推薦一款刷題神奇哦 點擊鏈接訪問牛客網 各大互聯網大廠面試真題。從基礎到入階乃至原理刨析類面試題 應有盡有&#xff0c;趕快來裝備自己吧&#xff01;助你面試穩操勝券&#xff0c;solo全場面試官 你還在以為CSDN僅僅是一個簡簡單單…

理解JavaScript中的原型繼承(2)

兩年前在我學習JavaScript的時候我就寫過兩篇關于原型繼承的博客&#xff1a; 理解JavaScript中原型繼承 JavaScript中的原型繼承 這兩篇博客講的都是原型的使用&#xff0c;其中一篇還有我學習時的錯誤理解。今天看《Understanding Scopes》這讓我從新思考了一下原型繼承&…

深入Vue原理_全面剖析發布訂閱模式

文章目錄發布訂閱模式優化優化思路思考理解發布訂閱模式(自定義事件)收集更新函數觸發更新函數6.5 總結總結寫在最后本期推薦歡迎各位小伙伴們&#xff01; 為大家推薦一款刷題神奇哦 點擊鏈接訪問牛客網 各大互聯網大廠面試真題。從基礎到入階乃至原理刨析類面試題 應有盡有&a…

前端面試系列-JS 異步編程

并發與并行的區別&#xff1f; 并發是宏觀概念&#xff0c;我分別有任務 A 和任務 B&#xff0c;在一段時間內通過任務間的切換完成了這兩個任務&#xff0c;這種情況就可以稱之為并發。并行是微觀概念&#xff0c;假設 CPU 中存在兩個核心&#xff0c;那么我就可以同時完成任務…

web前端發展歷程

總覽前端發展史前言瀏覽器的發展史走進前端HTMLCSSjavaScript小前端時代大前端時代寫在最后前言 目前在IT公司中前端的崗位越來越成為不可或缺的&#xff0c;前端的地位也愈見明顯&#xff0c;很多學校已經體系的傳授前端課程&#xff0c;眾多培訓機構也將前端知識作為了主流課…

修改wordpress上傳文件大小限制

1. 登陸wordpress使用的數據庫&#xff0c;切換到使用的database 2. 操作如下&#xff1a; > select meta_key from wp_sitemeta; > select meta_key,meta_value from wp_sitemeta where meta_keyfileupload_maxk; 修改為20M: > update wp_sitemeta set meta_value204…

php的符號的排序大小

轉載于:https://www.cnblogs.com/cjjjj/p/10433334.html

淺談 HTTP 和 HTTPS

很多前端伙伴問題有沒有體系的面試題&#xff1f; 今天為大家推薦一款刷題神奇哦 點擊鏈接訪問牛客網 各大互聯網大廠面試真題。從基礎到入階乃至原理刨析類面試題 應有盡有&#xff0c;趕快來裝備自己吧&#xff01;助你面試穩操勝券&#xff0c;solo全場面試官 淺談 HTTP 和 …

Ubuntu 搭建 GitLab 筆記 ***

簡介 GitLab 社區版可以提供許多與 GitHub 相同的功能&#xff0c;且部署在屬于自己的機器上&#xff0c;我們會因為網絡及其他一些問題而不便使用 GitHub &#xff0c;這時部署一個 GitLab 是最好的選擇。 下載 GitLab 并安裝 我的環境是 Ubuntu 16.04 下進行部署操作。 GitLa…

在瀏覽器輸入URL到頁面展示發生了什么?

輸入URL后查詢緩存DNS服務器TCP三次握手HTTP協議包瀏覽器處理HTML文檔TCP 和 UDP 的區別寫在最后很多前端伙伴問題有沒有體系的面試題&#xff1f; 今天為大家推薦一款刷題神奇哦 點擊鏈接訪問牛客網 各大互聯網大廠面試真題。從基礎到入階乃至原理刨析類面試題 應有盡有&#…

iOS 高級去水印,涂鴉去水印

目前在研究一下圖像的處理&#xff0c;看了一下相關的軟件&#xff0c;比如&#xff1a;《去水印大師》&#xff0c;究竟去水印是怎么處理的呢&#xff1f;看圖分析。 一共是三個功能&#xff1a;快速去水印、高級去水印、涂鴉去水印 快速去水印&#xff1a;暫時沒找到好的處理…

Failed to execute goal maven-gpg-plugin 1.5 Sign

問題描述&#xff1a; 解決辦法&#xff1a;跳過maven-gpg-plugin <build> <pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><configuration&g…

打造硬核敲門磚——簡歷

文章目錄 前言打造簡歷篇幅模板個人信息專業技能工作經歷項目經歷教育經歷個人總結簡歷格式寫在最后前言 作為高校的學生,你是否已經開始設想你以后的工作?作為職場的員工,你是否已經準備更換下一份工作了?不論你現在是什么身份、處于什么階段,這篇文章都能夠幫到你,只要…

Robot Framework 內置變量

Robot Framework 內置變量 轉自&#xff1a;https://blog.csdn.net/qq_26886929/article/details/53907755 Robot Framework 內部提供了一下直接可用的內置變量 1. 操作系統相關變量 內置的操作系統相關的變量&#xff0c;減少了測試數據對操作系統之間的差異性的關注 RF 中可用…

一文搞懂this指向

前言 那你說一下 js 中的 this 指向吧&#xff01;這句話已經成為面試官口中的高頻面試題&#xff0c;作為前端開發的我們&#xff0c;你真的搞懂了 this 指向了嗎&#xff1f;快來跟我一起來查漏補缺吧&#xff01;通過幾個小案例讓大家更能直白的理解 this 指向。 很多前端伙…

難怪大家丟掉了postman而選擇 Apifox

前言 當下采用前后端分離模式開發Web應用已經成為氣候&#xff0c;在開發階段有一個不成文的規定則是 項目開發后端先行 但是作為前端開發工程師的我們&#xff0c;難道在搭建完頁面后只能等待后端的接口么&#xff1f;這樣的話我們則完全被后端開發限制住了。在前面跟大家介紹…