linux取全进程信息,取某个进程信息

获取进程全部信息

[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==行号
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值