知识屋:更实用的电脑技术知识网站
所在位置:首页 > 操作系统 > linux

ps命令常用参数

发布时间:2014-09-05 13:36:38作者:知识屋

ps命令常用参数
 
一直都用ps命令,但是很少去琢磨其中参数的含义,很多人都和我一样吧. 今天花点时间看一下,
首先是我常用的命令
[plain] 
ps -def  
 
-d Select all processes except session leaders.
什么是session leader。
[plain] 
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.
 
-e 参数等同于 -A,
[plain] 
-e     Select all processes.  Identical to -A.  
 
-f 参数 显示完整格式
[plain] 
-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 参数
[plain] 
-a     Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.  
-x 参数 和tty有关,tty会在另一篇文章中解释
[plain] 
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 参数
[plain] 
-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参数,比如
[plain] 
$ 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=
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜