Linux ps命令:报告当前进程的快照。
Linux ps命令 功能描述
使用ps命令可以查看进程信息,可以确定有哪些进程正在运行及进程运行的状态、进程是否结束、进程有没有僵死,以及哪些进程占用了过多的资源等。
Linux ps命令 语法
ps [选项]
命令中各选项的含义如表所示。
ps命令输出字段描述如表所示。
Linux ps命令 示例
显示所有的进程
[root@rhel ~]# ps -e
PID TTY TIME CMD
1? 00:00:02 init
2? 00:00:00 kthreadd
3? 00:00:00 migration/0
4? 00:00:00 ksoftirqd/0
5? 00:00:00 migration/0
6? 00:00:00 watchdog/0
7? 00:00:04 events/0
8? 00:00:00 cgroup
9? 00:00:00 khelper
10? 00:00:00 netns
11? 00:00:00 async/mgr
12? 00:00:00 pm
13? 00:00:00 sync_supers
14? 00:00:00 bdi-default
15? 00:00:00 kintegrityd/0
16? 00:00:00 kblockd/0
........................(省略)
显示所有不带控制台终端的进程,并显示用户名和进程的起始时间
[root@rhel ~]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.8 0.1 19352 1548? Ss 00:44 0:02/sbin/init
root 2 0.0 0.0 0 0? S 00:44 0:00[kthreadd]
root 3 0.0 0.0 0 0? S 00:44 0:00[migration/0]
root 4 0.0 0.0 0 0? S 00:44 0:00[ksoftirqd/0]
root 5 0.0 0.0 0 0? S 00:44 0:00[migration/0]
root 6 0.0 0.0 0 0? S 00:44 0:00[watchdog/0]
root 7 0.1 0.0 0 0? R 00:44 0:00[events/0]
root 8 0.0 0.0 0 0? S 00:44 0:00[cgroup]
root 9 0.0 0.0 0 0? S 00:44 0:00[khelper]
root 10 0.0 0.0 0 0? S 00:44 0:00[netns]
root 11 0.0 0.0 0 0? S 00:44 0:00[async/mgr]
root 12 0.0 0.0 0 0? S 00:44 0:00[pm]
root 13 0.0 0.0 0 0? S 00:44 0:00[sync_supers]
root 14 0.0 0.0 0 0? S 00:44 0:00[bdi-default]
root 15 0.0 0.0 0 0? S 00:44 0:00[kintegrityd/0]
root 16 0.1 0.0 0 0? S 00:44 0:00[kblockd/0]
root 17 0.0 0.0 0 0? S 00:44 0:00[kacpid]
........................(省略)
查看crond进程是否正在运行
[root@rhel ~]# ps -ef|grep crond
root 1779 1 0 00:45? 00:00:02 crond
//crond进程正在运行,其进程号为1779
显示当前系统进程
[root@rhel ~]# ps
PID TTY TIME CMD
2580 pts/1 00:00:00 bash
2608 pts/1 00:00:00 ps
在显示进程的时候显示用户名和进程的起始时间
[root@rhel ~]# ps -u
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1902 0.0 0.0 4060 584 tty2 Ss+ 00:47 0:00/sbin/mingetty/dev/tty2
root 1904 0.0 0.0 4060 580 tty3 Ss+ 00:47 0:00/sbin/mingetty/dev/tty3
root 1906 0.0 0.0 4060 580 tty4 Ss+ 00:47 0:00/sbin/mingetty/dev/tty4
root 1912 0.0 0.0 4060 580 tty5 Ss+ 00:47 0:00/sbin/mingetty/dev/tty5
root 1914 0.0 0.0 4060 584 tty6 Ss+ 00:47 0:00/sbin/mingetty/dev/tty6
root 1931 1.6 4.0 13222040532 tty1 Ss+ 00:47 0:04/usr/bin/Xorg:0-nr-verbose-audit 4-auth/var/run/gdm/auth-for-gd
root 2562 0.0 0.1108296 1888 pts/0 Ss+ 00:48 0:00/bin/bash
root 2580 0.0 0.1108296 1884 pts/1 Ss 00:49 0:00-bash
root 2609 0.0 0.1110224 1172 pts/1 R+ 00:51 0:00 ps-u
显示root用户的进程
[root@rhel ~]# ps -u root
PID TTY TIME CMD
1? 00:00:02 init
2? 00:00:00 kthreadd
3? 00:00:00 migration/0
4? 00:00:00 ksoftirqd/0
5? 00:00:00 migration/0
6? 00:00:00 watchdog/0
7? 00:00:00 events/0
8? 00:00:00 cgroup
9? 00:00:00 khelper
10? 00:00:00 netns
11? 00:00:00 async/mgr
12? 00:00:00 pm
13? 00:00:00 sync_supers
14? 00:00:00 bdi-default
15? 00:00:00 kintegrityd/0
16? 00:00:00 kblockd/0
17? 00:00:00 kacpid
18? 00:00:00 kacpi_notify
19? 00:00:00 kacpi_hotplug
........................(省略)
显示tty1终端下的进程
[root@rhel ~]# ps -t tty1
显示进程号为1779的进程
[root@rhel ~]# ps -p 1779
PID TTY TIME CMD
1779? 00:00:02 crond