ps命令常用参数

一直都用ps命令,但是很少去琢磨其中参数的含义,很多人都和我一样吧. 今天花点时间看一下,

首先是我常用的命令

ps -def

-d Select all processes except session leaders.

什么是session leader。参考该解释:http://www.win.tue.nl/~aeb/linux/lk/lk-10.html#ss10.3

Every process group is in a unique session. (When the process is created, it becomes a member of the session of its parent.) By convention, the session ID of a session equals the process ID of the first member of the session, called the session leader. A process finds the ID of its session using the system call getsid().

Every session may have a controlling tty, that then also is called the controlling tty of each of its member processes. A file descriptor for the controlling tty is obtained by opening /dev/tty. (And when that fails, there was no controlling tty.) Given a file descriptor for the controlling tty, one may obtain the SID using tcgetsid(fd).

A session is often set up by a login process. The terminal on which one is logged in then becomes the controlling tty of the session. All processes that are descendants of the login process will in general be members of the session.

进程是按照进程组管理的,进程组又属于session。关系如下:

每个session拥有一个或者多个进程组,每个进程组拥有一个或多个进程。第一个属于某个session的进程id就是这个session的 leader, session id就用它的进程id。

和进程相关的id有几种,

进程id, 父进程id, 进程组id 和 session id.

参考:http://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps


-e 参数等同于 -A,

-e     Select all processes.  Identical to -A.


-f 参数 显示完整格式
-f     Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns.  It also causes the command arguments to be
              printed.  When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added.  See the c option, the format keyword args, and the
              format keyword comm.

不过还有个常用的方式:

ps axu

不同于ps -def 用标准风格,这是BSD风格(不用-作为引导参数), BSD风格会在另一篇博客中介绍。

-a 参数

-a     Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.
-x 参数 和tty有关,tty会在另一篇文章中解释

x      Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when
              the ps personality setting is BSD-like.  The set of processes selected in this manner is in addition to the set of processes selected by other means.  An
              alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the
              a option.
-u 参数

-u userlist
              Select by effective user ID (EUID) or name.  This selects the processes whose effective user name or ID is in userlist.

              The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)).  Identical to U and --user.



还有一种,通过直接输入命令查找,用-C参数,比如

$ UNIX95= ps -C nginx
  PID TTY          TIME CMD
 1258 ?        00:00:00 nginx
 1259 ?        00:00:00 nginx
CHN\shu6889@sloop2:~$ ps aux | grep nginx
root      1258  0.0  0.0  31188  1028 ?        Ss   09:24   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
root      1259  0.0  0.0  47312  2708 ?        S    09:24   0:00 nginx: worker process                   
70780027  4336  0.0  0.0  13652   976 pts/1    S+   10:40   0:00 grep --color=auto nginx

要注意,前面需要输入UNIX95=




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值