[实践OK]ps -eo 自定义查看pid ppid 虚拟内存vsz 实际物理内存rss和命令行cmd的输出方法。 不指定

jackxiang 2018-9-26 23:31 | |
背景:在多进程时,用那个叫物理内存、虚拟内存的,怎么看?https://blog.csdn.net/i_am_jojo/article/details/7862362

ps -eo pid,ppid,gid,sid,tty,cmd --forest|less


  -e     Select all processes.  Identical to -A.
  -o format
              User-defined format.  format is a single argument in the form of a blank-separated or comma-separated
              list, which offers a way to specify individual output columns.  The recognized keywords are described
              in the STANDARD FORMAT SPECIFIERS section below.  Headers may be renamed (ps -o pid,ruser=RealUser -o
              comm=Command) as desired.  If all column headers are empty (ps -o pid= -o comm=) then the header line
              will not be output.  Column width will increase as needed for wide headers; this may be used to widen
              up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).  Explicit width control (ps opid,
              wchan:42,cmd) is offered too.  The behavior of ps -o pid=X,comm=Y varies with personality; output may
              be one column named "X,comm=Y" or two columns named "X" and "Y".  Use multiple -o options when in
              doubt.  Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are
              macros that may be used to choose the default UNIX or BSD columns.

       -C cmdlist
              Select by command name.  This selects the processes whose executable name is given in cmdlist.
       --forest
              ASCII art process tree.

#ps -eo 'pid,ppid,gid,sid,tty,cmd' |grep Easy
26721 62388     0 62388 pts/4    EasySwoole
26722 26721     0 62388 pts/4    EasySwoole
26744 26722     0 62388 pts/4    EasySwoole.Crontab
31311 26722     0 62388 pts/4    EasySwoole.Worker.0
31312 26722     0 62388 pts/4    EasySwoole.Worker.1
31313 26722     0 62388 pts/4    EasySwoole.Worker.2
31314 26722     0 62388 pts/4    EasySwoole.Worker.3
31315 26722     0 62388 pts/4    EasySwoole.Worker.4
31316 26722     0 62388 pts/4    EasySwoole.Worker.5
31317 26722     0 62388 pts/4    EasySwoole.Worker.6
31318 26722     0 62388 pts/4    EasySwoole.Worker.7
31319 26722     0 62388 pts/4    EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4    EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4    EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4    EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4    EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4    EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4    EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4    EasySwoole.TaskWorker.15

对Crontab进行查看:
lsof -nPp 26744|grep swoole.log
php     26744 root   11u      REG              253,0  39874179 100744037 /data/logs/php/swoole.lo

#lsof -nPp 26721 |grep LISTEN
php     26721 root    3u     IPv4             763966       0t0       TCP *:8080 (LISTEN)
php     26721 root   10u     IPv4             762762       0t0       TCP 127.0.0.1:9000 (LISTEN)


26721 62388     0 62388 pts/4         \_ EasySwoole
26722 26721     0 62388 pts/4             \_ EasySwoole
26742 26722     0 62388 pts/4                 \_ HotReload
26743 26722     0 62388 pts/4                 \_ KafkaAddFormId
26744 26722     0 62388 pts/4                 \_ EasySwoole.Crontab
31311 26722     0 62388 pts/4                 \_ EasySwoole.Worker.0
31312 26722     0 62388 pts/4                 \_ EasySwoole.Worker.1
31313 26722     0 62388 pts/4                 \_ EasySwoole.Worker.2
31314 26722     0 62388 pts/4                 \_ EasySwoole.Worker.3
31315 26722     0 62388 pts/4                 \_ EasySwoole.Worker.4
31316 26722     0 62388 pts/4                 \_ EasySwoole.Worker.5
31317 26722     0 62388 pts/4                 \_ EasySwoole.Worker.6
31318 26722     0 62388 pts/4                 \_ EasySwoole.Worker.7
31319 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.15

ps --headers -eo pid,ppid,GID,tty,sid,vsz,rss,cmd -C EasySwoole


To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm

Print only the process IDs of syslogd:
          ps -C syslogd -o pid=

相查看树,能看到进程的继承关系:
ps -eo 'pid,ppid,vsz,rss,cmd' --forest
3078  1214  48620  3032  \_ sshd: xiangdong [priv]
3084  3078  48752  1680      \_ sshd: xiangdong@pts/0,pts/1,pts/2
3085  3084 108352  1788          \_ -bash
3644  3085 189592  2940          |   \_ sudo su -
3645  3644 163756  1964          |       \_ su -
3646  3645 108476  1908          |           \_ -bash
5416  3646 108412  1200          |               \_ ps -eo pid,ppid,vsz,rss,cmd --forest
5417  3646 105460   816          |               \_ less

1481     1  55604  1460 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
1484  1481  76816 22864  \_ nginx: worker process                                          
1485  1481  76816 22936  \_ nginx: worker process                                          
1486  1481  76816 22936  \_ nginx: worker process                                          
1487  1481  76816 22936  \_ nginx: worker process  

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/9908/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2019-4-5 23:12
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]