获取进程全部信息
[root@hansontest ~]# ps -aux|less
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 191268 3692 ? Ss 7月12 2:09 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 7月12 0:01 [kthreadd]
root 3 0.0 0.0 0 0 ? S 7月12 0:14 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 7月12 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 7月12 0:02 [migration/0]
root 8 0.0 0.0 0 0 ? S 7月12 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 7月12 17:10 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 7月12 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 7月12 0:16 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 7月12 0:13 [watchdog/1]
root 13 0.0 0.0 0 0 ? S 7月12 0:02 [migration/1]
root 14 0.0 0.0 0 0 ? S 7月12 0:11 [ksoftirqd/1]
root 16 0.0 0.0 0 0 ? S< 7月12 0:00 [kworker/1:0H]
root 17 0.0 0.0 0 0 ? S 7月12 0:12 [watchdog/2]
root 18 0.0 0.0 0 0 ? S 7月12 0:02 [migration/2]
root 19 0.0 0.0 0 0 ? S 7月12 0:14 [ksoftirqd/2]
root 21 0.0 0.0 0 0 ? S< 7月12 0:00 [kworker/2:0H]
root 22 0.0 0.0 0 0 ? S 7月12 0:12 [watchdog/3]
root 23 0.0 0.0 0 0 ? S 7月12 0:02 [migration/3]
root 24 0.0 0.0 0 0 ? S 7月12 0:14 [ksoftirqd/3]
root 26 0.0 0.0 0 0 ? S< 7月12 0:00 [kworker/3:0H]
root 28 0.0 0.0 0 0 ? S 7月12 0:00 [kdevtmpfs]
获取某一列信息
[root@hansontest ~]# ps -aux |awk -F " " '{print $2}'
PID
1
2
3
5
7
8
9
10
11
12
13
14
16
17
18
19
21
22
23
24
26
28
29
30
31
32
33
34
35
36
37
$2,这里的2是列序号
获取某个进程的某一行某一列信息,(类似于excel中的某个单元格)
用grep+ 进程名过滤可以得到该进程的id
[root@hansontest ~]# ps -aux|grep "/usr/lib64/firefox/firefox" |awk -F " " '{print $2}'
13623
[root@hansontest ~]#
使用pgrep+进程名同样
[root@hansontest ~]# pgrep firefox
13924
使用id号获取进程信息
[root@hansontest ~]# ps -q 13924
PID TTY TIME CMD
13924 ? 00:00:03 firefox
同样的,加上awk可以获取到具体的某个信息
[root@hansontest ~]# ps -q 13924 | awk -F " " 'NR==2 {print $4}'
firefox
使用grep过滤获取进程某个信息
[root@hansontest ~]# ps -aux|grep "/usr/lib64/firefox/firefox" |awk -F " " 'NR==1 {print $2}'
13924
获取某进程某一行的信息
[root@hansontest ~]# ps -aux|grep "/usr/lib64/firefox/firefox" |awk -F " " 'NR==1'
root 13924 1.2 2.2 2219628 177416 ? Sl 18:36 0:03 /usr/lib64/firefox/firefox
[root@hansontest ~]#
NR==行号