柚子快报邀请码778899分享:Linux 进程状态

http://yzkb.51969.com/

1. 列出所有的运行的进程 (ps -ef, ps -aux),在BSD机器上,需要使用ps -aux $ ps -efroot     26551     5  0 Feb10 ?        00:03:41 [pdflush]root     26570     5  0 Feb10 ?        00:00:20 [pdflush]root     30344  3382  0 Feb21 ?        00:00:11 sshd: root@pts/14root     30365 30344  0 Feb21 pts/14   00:00:02 -bashroot     30393  3382  0 Feb21 ?        00:00:10 sshd: root@pts/15Where:    -e to display all the processes.    -f to display full format listing.2. 基于用户或运行的程序来列出进程 (ps -u, ps -C)

-u选项用来显示只属于此user的进程。多个用户时使用逗号隔开。$ ps -f -u wwwrun,postfixUID        PID  PPID  C STIME TTY          TIME CMDpostfix   7457  7435  0 Mar09 ?        00:00:00 qmgr -l -t fifo -uwwwrun    7495  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confwwwrun    7496  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confwwwrun    7497  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confwwwrun    7498  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confwwwrun    7499  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confwwwrun   10078  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confwwwrun   10082  7491  0 Mar09 ?        00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.confpostfix  15677  7435  0 22:23 ?        00:00:00 pickup -l -t fifo -u通常我们使用类似 “ps -aux | grep command”的命令来获得运行命令的进程,但是ps自身提供了选项-C来完成类似的任务。下列的命令显示所有进程中包含 tatad.pl的进程.$ ps -f -C tatad.plUID        PID  PPID  C STIME TTY          TIME CMDroot      9576     1  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9577  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9579  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9580  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9581  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9582  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot     12133  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plNote: We can create aliases for ps command to list processes based on commands, users or groups.

 

3. 根据进程id或pid来列出进程Each process will be assigned with the unique Process ID (PID).When you launch some application, it might fork number of processes and each sub process will have its own PID. So, each process will have its own process id and parent processid.For all the processes that a process forks will have the same PPID (parent process identifier). The following method is used to get a list of processes with a particular PPID.$ ps -f --ppid 9576UID        PID  PPID  C STIME TTY          TIME CMDroot      9577  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9579  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9580  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9581  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot      9582  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plroot     12133  9576  0 Mar09 ?        00:00:00 /opt/tata/perl/bin/perl /opt/tata/bin/tatad.plThe following example is to list the processes which has given PID.$ ps -f  -p 25009,7258,2426UID        PID  PPID  C STIME TTY          TIME CMDroot      2426     4  0 Mar09 ?        00:00:00 [reiserfs/0]root      7258     1  0 Mar09 ?        00:00:00 /usr/sbin/nscdpostfix  25009  7435  0 00:02 ?        00:00:00 pickup -l -t fifo -u4. 以树形列出进程的关系(ps –forest) 与pstree命令类似The example below display the process Id and commands in a hierarchy. –forest is an argument to ps command which displays ASCII art of process tree. From this tree, we can identify which is the parent process and the child processes it forked in a recursive manner.$ ps -e -o pid,args --forest  468  \_ sshd: root@pts/7  514  |   \_ -bash17484  \_ sshd: root@pts/1117513  |   \_ -bash24004  |       \_ vi ./790310__11117/journal15513  \_ sshd: root@pts/115522  |   \_ -bash 4280  \_ sshd: root@pts/5 4302  |   \_ -bashNote: You can also use tree and pstree command to displays process in a nice tree structure.

 

5. 显示进程运行的时间(ps -o pid,etime=)If you want the get the elapsed time for the processes which are currently running ps command provides etime which provides the elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.The below command displays the elapsed time for the process IDs 1 (init) and process id 29675.For example “10-22:13:29″ in the output represents the process init is running for 10days, 22hours,13 minutes and 29seconds. Since init process starts during the system startup, this time will be same as the output of the ‘uptime’ command.# ps -p 1,29675 -o pid,etime=  PID    1 10-22:13:2929675  1-02:58:46

柚子快报邀请码778899分享:Linux 进程状态

http://yzkb.51969.com/

好文链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。