Linux基础:目录名称含义,监测程序
Linux 文件系统
常见Linux目录名称:
常见的目录名均基于文件系统层级标准(filesystem hierarchy stanard,FHS)。FHS偶尔会进行更新,可能有些Linux发行版人在使用旧的FHS标准。最新的FHS标准可以访问其官方主页: ps 命令查看进程当程序运行在系统上时,称之为进程(process)。要监测这些进程,就需要熟悉ps命令的用法。 默认情况下,ps命令只会显示运行在当前控制台下的属于当前用户的进程: $ ps PID TTY TIME CMD 4763 pts/0 00:00:00 bash 4782 pts/0 00:00:00 ps $ 在这里,当前用户只运行了bash shell(注意,shell也只是运行在系统上的另一个进程而已),以及ps命令本身。 Linux系统中使用的GNU ps命令支持3种不同类型的命令行参数:
Unix风格的参数Unix风格的参数是从贝尔实验室开发的AT&T Unix系统上原有的ps命令继承下来的。
命令参数列出了很多,但是不一定全。使用ps命令的关键不在于记住多少可用的参数。而是只要记住最有用的一些参数组合就好了。 ps -ef $ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 18:23 ? 00:00:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 2 0 0 18:23 ? 00:00:00 [kthreadd] root 3 2 0 18:23 ? 00:00:00 [ksoftirqd/0] root 5 2 0 18:23 ? 00:00:00 [kworker/0:0H] root 6 2 0 18:23 ? 00:00:00 [kworker/u2:0] root 7 2 0 18:23 ? 00:00:00 [migration/0] root 8 2 0 18:23 ? 00:00:00 [rcu_bh] root 9 2 0 18:23 ? 00:00:00 [rcu_sched] root 10 2 0 18:23 ? 00:00:00 [lru-add-drain] ...... root 4250 1 0 18:23 ? 00:00:00 /usr/sbin/hypervkvpd -n root 4251 1 0 18:23 ? 00:00:00 /usr/sbin/sshd -D root 4253 1 0 18:23 ? 00:00:01 /usr/bin/python2 -Es /usr/sbin/tuned -l -P root 4254 1 0 18:23 ? 00:00:00 /usr/sbin/rsyslogd -n root 4515 1 0 18:23 ? 00:00:00 /usr/libexec/postfix/master -w postfix 4532 4515 0 18:24 ? 00:00:00 qmgr -l -t unix -u root 4569 4251 0 18:24 ? 00:00:00 sshd: [email?protected]/0 root 4763 4569 0 18:24 pts/0 00:00:00 -bash postfix 4931 4515 0 20:04 ? 00:00:00 pickup -l -t unix -u root 4938 2 0 20:31 ? 00:00:00 [kworker/0:3] root 4944 2 0 20:46 ? 00:00:00 [kworker/0:2] root 4947 2 0 20:51 ? 00:00:00 [kworker/0:0] root 4949 4763 0 20:53 pts/0 00:00:00 ps -ef $ 每列的信息说明:
ps -el $ ps -el F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 1 0 0 80 0 - 32005 ep_pol ? 00:00:01 systemd 1 S 0 2 0 0 80 0 - 0 kthrea ? 00:00:00 kthreadd 1 S 0 3 2 0 80 0 - 0 smpboo ? 00:00:00 ksoftirqd/0 1 S 0 5 2 0 60 -20 - 0 worker ? 00:00:00 kworker/0:0H 1 S 0 6 2 0 80 0 - 0 worker ? 00:00:00 kworker/u2:0 1 S 0 7 2 0 -40 - - 0 smpboo ? 00:00:00 migration/0 1 S 0 8 2 0 80 0 - 0 rcu_gp ? 00:00:00 rcu_bh 1 R 0 9 2 0 80 0 - 0 - ? 00:00:00 rcu_sched 1 S 0 10 2 0 60 -20 - 0 rescue ? 00:00:00 lru-add-drain ...... 4 S 0 4250 1 0 80 0 - 10025 poll_s ? 00:00:00 hypervkvpd 4 S 0 4251 1 0 80 0 - 28215 poll_s ? 00:00:00 sshd 4 S 0 4253 1 0 80 0 - 143481 poll_s ? 00:00:02 tuned 4 S 0 4254 1 0 80 0 - 55687 poll_s ? 00:00:00 rsyslogd 5 S 0 4515 1 0 80 0 - 22412 ep_pol ? 00:00:00 master 4 S 89 4532 4515 0 80 0 - 22455 ep_pol ? 00:00:00 qmgr 4 S 0 4569 4251 0 80 0 - 39183 poll_s ? 00:00:00 sshd 4 S 0 4763 4569 0 80 0 - 28859 do_wai pts/0 00:00:00 bash 4 S 89 4931 4515 0 80 0 - 22438 ep_pol ? 00:00:00 pickup 1 S 0 4972 2 0 80 0 - 0 worker ? 00:00:00 kworker/0:0 1 S 0 4973 2 0 80 0 - 0 worker ? 00:00:00 kworker/0:3 1 S 0 4974 2 0 80 0 - 0 worker ? 00:00:00 kworker/0:1 1 R 0 4977 2 0 80 0 - 0 - ? 00:00:00 kworker/0:2 0 R 0 4979 4763 0 80 0 - 38309 - pts/0 00:00:00 ps $ ^ 每列的信息说明:
BSD风格的参数伯克利软件发行版(Berkeley software distribution,BSD)是加州大学伯克利分校开发的一个Unix版本。
Unix和BSD类型的参数有很多是重复的,大多数情况下,选择自己重用的格式的参数即可。 $ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 128000 6540 ? Ss 09:19 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 2 0.0 0.0 0 0 ? S 09:19 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 09:19 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 09:19 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S 09:19 0:00 [kworker/u2:0] root 7 0.0 0.0 0 0 ? S 09:19 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 09:19 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? R 09:19 0:00 [rcu_sched] root 10 0.0 0.0 0 0 ? S< 09:19 0:00 [lru-add-drain] ...... root 4256 0.0 0.0 40100 1540 ? Ss 09:19 0:00 /usr/sbin/hypervkvpd -n root 4258 0.0 0.2 112860 4296 ? Ss 09:19 0:00 /usr/sbin/sshd -D root 4259 0.0 0.4 222748 7800 ? Ssl 09:19 0:00 /usr/sbin/rsyslogd -n root 4261 0.0 0.9 573924 17144 ? Ssl 09:19 0:00 /usr/bin/python2 -Es /usr/sbin/tuned -l -P root 4503 0.0 0.1 89648 2100 ? Ss 09:19 0:00 /usr/libexec/postfix/master -w postfix 4516 0.0 0.2 89752 4068 ? S 09:19 0:00 pickup -l -t unix -u postfix 4517 0.0 0.2 89820 4096 ? S 09:19 0:00 qmgr -l -t unix -u root 4770 0.0 0.3 156732 5524 ? Ss 09:28 0:00 sshd: [email?protected]/0 root 4774 0.0 0.1 115436 2068 pts/0 Ss 09:28 0:00 -bash root 4829 0.0 0.0 0 0 ? S 09:35 0:00 [kworker/0:3] root 4887 0.0 0.0 0 0 ? S 09:40 0:00 [kworker/0:1] root 4901 0.0 0.0 0 0 ? R 09:45 0:00 [kworker/0:0] root 4903 0.0 0.1 155360 1884 pts/0 R+ 09:48 0:00 ps aux $ 每列的信息说明:
BSD风格表示的进程状态码更详细。双字符码能比Unix风格输出的单字符状态码更清楚地表示进程的当前状态。
GNU长参数最后,GNU开发人员在最近改进过的ps命令中加入了另外一些参数。其中一些复制了现有的Unix或BSD类型的参数,而另一些则提供了新功能。
部分GNU长参数可以和Unix或BSD风格的参数混用来定制输出。 --forest参数 显示进程的层级信息 $ ps -ef --forest UID PID PPID C STIME TTY TIME CMD root 2 0 0 09:19 ? 00:00:00 [kthreadd] root 3 2 0 09:19 ? 00:00:00 _ [ksoftirqd/0] ...... root 4256 1 0 09:19 ? 00:00:00 /usr/sbin/hypervkvpd -n root 4258 1 0 09:19 ? 00:00:00 /usr/sbin/sshd -D root 4770 4258 0 09:28 ? 00:00:00 _ sshd: [email?protected]/0 root 4774 4770 0 09:28 pts/0 00:00:00 _ -bash root 5001 4774 0 11:12 pts/0 00:00:00 _ ps -ef --forest root 4259 1 0 09:19 ? 00:00:00 /usr/sbin/rsyslogd -n root 4261 1 0 09:19 ? 00:00:01 /usr/bin/python2 -Es /usr/sbin/tuned -l -P root 4503 1 0 09:19 ? 00:00:00 /usr/libexec/postfix/master -w postfix 4517 4503 0 09:19 ? 00:00:00 _ qmgr -l -t unix -u postfix 4958 4503 0 11:00 ? 00:00:00 _ pickup -l -t unix -u $ Unix风格的-H参数也有同样的功能,但是效果没有这个好: $ ps -efH UID PID PPID C STIME TTY TIME CMD root 2 0 0 09:19 ? 00:00:00 [kthreadd] root 3 2 0 09:19 ? 00:00:00 [ksoftirqd/0] ...... root 4256 1 0 09:19 ? 00:00:00 /usr/sbin/hypervkvpd -n root 4258 1 0 09:19 ? 00:00:00 /usr/sbin/sshd -D root 4770 4258 0 09:28 ? 00:00:00 sshd: [email?protected]/0 root 4774 4770 0 09:28 pts/0 00:00:00 -bash root 5002 4774 0 11:13 pts/0 00:00:00 ps -efH root 4259 1 0 09:19 ? 00:00:00 /usr/sbin/rsyslogd -n root 4261 1 0 09:19 ? 00:00:01 /usr/bin/python2 -Es /usr/sbin/tuned -l -P root 4503 1 0 09:19 ? 00:00:00 /usr/libexec/postfix/master -w postfix 4517 4503 0 09:19 ? 00:00:00 qmgr -l -t unix -u postfix 4958 4503 0 11:00 ? 00:00:00 pickup -l -t unix -u $ BSD风格的f参数也是这个功能,效果和--forest一样。 top 命令实时监测进程top命令和ps命令相似,都能够显示进程信息,并且是实时的: $ top top - 12:01:28 up 2:41,1 user,load average: 0.00,0.01,0.05 Tasks: 97 total,2 running,95 sleeping,0 stopped,0 zombie %Cpu(s): 0.0 us,0.3 sy,0.0 ni,99.7 id,0.0 wa,0.0 hi,0.0 si,0.0 st KiB Mem : 1816668 total,335380 free,1325796 used,155492 buff/cache KiB Swap: 2097148 total,2097148 free,0 used. 321636 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5028 root 20 0 161880 2216 1572 R 0.3 0.1 0:00.06 top 1 root 20 0 128000 6544 4136 S 0.0 0.4 0:01.12 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 6 root 20 0 0 0 0 S 0.0 0.0 0:00.03 kworker/u2:0 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 S 0.0 0.0 0:00.35 rcu_sched 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain 11 root rt 0 0 0 0 S 0.0 0.0 0:00.11 watchdog/0 13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs 14 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns 15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback 17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd 18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd 22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md 23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 edac-poller 24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 watchdogd 30 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kswapd0 31 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd 32 root 39 19 0 0 0 S 0.0 0.0 0:00.06 khugepaged 33 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto 41 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kthrotld 输出的第一部分显示的是系统的概况:
默认情况下,top启动后按%CPU排序,可按f指定其他列。轮询时间默认是3.0秒,可按d修改。按q是退出。其他就不列举了。 结束进程在Linux中,进程之间通过信号来通信。大多数编写完善的程序都能接收和处理标准Unix进程信号。
kill命令 killall命令 killall命令支持通过进程名而不是PID来结束进程。killall命令也支持通配符。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |