【ps】关于Linux ps命令的妙用

How to get all process ids without ps command on Linux?

On Linux, all running process have "metadata" stored in the /proc filesystem.

#  for exe in /proc/*/exe; do ls -l $exe; done

# man  ps  

# ps -C sshd --no-header

# ps -C dockerd --no-header

-C cmdlist

Select by command name.  This selects the processes whose executable name is given in cmdlist.

you can use the long options --headers and --no-headers to enable printing headers each page or disable headers entirely, respectively.

#  ps -eo nlwp,pcpu,user,pid,ppid,args  --sort nlwp  

注:以 nlwp排序,默认正序

LWP -- 轻量级进程,即线程

NLWP --线程数,即 number of threads in process

#  ps -eo pid,cmd,%mem,%cpu --sort=-%mem

Thecommand is highly valuable for system admins during troubleshooting the system. 

You can display the processes list in a sorted manner to find out the highest memory usage processes.

#  ps -mp   ${pid}    -o   THREAD,tid,time

参数解释:

   -m:显示所有的线程

   -p:pid进程使用CPU的时间

   -o:该参数后是用户自定义格式。

  如:THREAD,tid,time表示线程、线程ID号、线程占用的时间。

$ ps -Hp   ${pid}  

参考

ps(1) — Linux manual page

https://man7.org/linux/man-pages/man1/ps.1.html

Linux PS command with examples

https://www.fosslinux.com/43296/linux-ps-command-with-examples.htm

How to get all process ids without ps command on Linux?

https://stackoverflow.com/questions/32913424/how-to-get-all-process-ids-without-ps-command-on-linux

What is the difference between ps and top command?

https://unix.stackexchange.com/questions/62176/what-is-the-difference-between-ps-and-top-command

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值