
然后 按P – 以 CPU 占用率大小的顺序排列进程列表
按M – 以内存占用率大小的顺序排列进程列表
另外,查看某一应用占用内存大小
方法一:通过进程号查看
# 例如查看kafka资源使用情况
# 查看kafka进程号
ps -ef | grep kafka
# 查看进程号占用资源(159156为ps得到的进程号)
top -p 159156
# 或者查看进程的status文件(159156为ps得到的进程号) ,VmRSS对应的值就是物理内存占用
cat /proc/159156/status
方法2:ps命令直接使用任务名
# 显示的第六个参数就是物理内存占用
ps -aux | grep kafka
# 查看内存占用前10名的程序
ps aux | sort -k4,4nr | head -n 10
3)对free -h 查看到的buff/cache 进行回收
# 在系统中除了内存将被耗尽的时候可以清缓存以外,我们还可以使用下面这个文件来人工触发缓存清除的 *** 作
cat /proc/sys/vm/drop_caches
# 这个文件可以设置的值分别为1、2、3。它们所表示的含义为:
# 表示清除 page cache。
echo 1 >/proc/sys/vm/drop_caches
# 表示清除回收 slab 分配器中的对象(包括目录项缓存和 inode 缓存)。slab 分配器是内核中管理内存的一种机制,其中很多缓存数据实现都是用的 page cache。
echo 2 >/proc/sys/vm/drop_caches
# 表示清除 page cache 和 slab 分配器中的缓存对象。
echo 3 >/proc/sys/vm/drop_caches
功能说明:将文本文件内容加以排序。语法:sort [-bcdfimMnr][-o<输出文件>][-t<分隔字符>][+<起始栏位>-<结束栏位>][--help][--verison][文件]
补充说明:sort可针对文本文件的内容,以行为单位来排序。
参数:
-b 忽略每行前面开始出的空格字符。
-c 检查文件是否已经按照顺序排序。
-d 排序时,处理英文字母、数字及空格字符外,忽略其他的字符。
-f 排序时,将小写字母视为大写字母。
-i 排序时,除了040至176之间的ASCII字符外,忽略其他的字符。
-m 将几个排序好的文件进行合并。
-M 将前面3个字母依照月份的缩写进行排序。
-n 依照数值的大小排序。
-o<输出文件> 将排序后的结果存入指定的文件。
-r 以相反的顺序来排序。
-t<分隔字符> 指定排序时所用的栏位分隔字符。
+<起始栏位>-<结束栏位> 以指定的栏位来排序,范围由起始栏位到结束栏位的前一栏位。
--help 显示帮助。
--version 显示版本信息
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下面通过几个例子来讲述Sort的使用。
用Sort命令对text文件中各行排序后输出其结果。请注意,在原文件的第二、三行上的第一个单词完全相同,该命令将从它们的第二个单词vegetables与fruit的首字符处继续进行比较。
$ cat text
vegetable soup
fresh vegetables
fresh fruit
lowfat milk
$ Sort text
fresh fruit
fresh vegetables
lowfat milk
vegetable soup
用户可以保存排序后的文件内容,或把排序后的文件内容输出至打印机。下例中用户把排序后的文件内容保存到名为result的文件中。
$ Sort text>result
以第2个字段作为排序关键字对文件example的内容进行排序。
$ Sort +1-2 example
对于file1和file2文件内容反向排序,结果放在outfile中,利用第2个字段的第一个字符作为排序关键字。
$ Sort -r -o outfile +1.0 -1.1 example
Sort排序常用于在管道中与其他命令连用,组合完成比较复杂的功能,如利用管道将当前工作目录中的文件送给Sort进行排序,排序关键字是第6个至第8个字段。
$ ls - l | Sort +5 - 7
$ ps -e -o " comm pid time"|Sort -d //按照command的首字母的字母顺序排序
Sort命令也可以对标准输入进行 *** 作。例如,如果您想把几个文件文本行合并,并对合并后的文本行进行排序,您可以首先用命令cat把多个文件合
并,然后用管道 *** 作把合并后的文本行输入给命令Sort,Sort命令将输出这些合并及排序后的文本行。在下面的例子中,文件veglist与文件
fruitlist的文本行经过合并与排序后被保存到文件clist中。
$ cat veglist fruitlist | Sort >clist
【 ps 】»语法
ps[必要参数][选择参数]
»功能
ps 命令:用来显示当前进程的状态
»类似命令 top kill pgrep
»执行权限 超级用户 普通用户
»命令属性 系统管理
»参数
必要参数
a 显示所有进程
-a 显示同一终端下的所有程序
-A 显示所有进程
c 显示进程的真实名称
-N 反向选择
-e 等于“-A”
e 显示环境变量
f 显示程序间的关系
-H 显示树状结构
r 显示当前终端的进程
T 显示当前终端的所有程序
u 指定用户的所有进程
选择参数
-C<命令>列出指定命令的状况
--lines<行数>每页显示的行数
--width<字符数>每页显示的字符数
--help 显示帮助信息
--version 显示版本显示
范例1: 显示所有进程信息
root@localhost :~# ps -A 显示进程信息
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 watchdog/0
6 ?00:00:00 events/0
7 ?00:00:00 cpuset
……
范例2: 显示指定用户信息
root@localhost :~# ps -u root //显示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 watchdog/0
6 ?00:00:00 events/0
7 ?00:00:00 cpuset
8 ?00:00:00 khelper
9 ?00:00:00 netns
10 ?00:00:00 async/mgr
11 ?00:00:00 pm
12 ?00:00:00 sync_supers
13 ?00:00:00 bdi-default
14 ?00:00:00 kintegrityd/0
15 ?00:00:02 kblockd/0
16 ?00:00:00 kacpid
……省略部分结果
30487 ?00:00:06 gnome-terminal
30488 ?00:00:00 gnome-pty-helpe
30489 pts/0 00:00:00 bash
30670 ?00:00:00 debconf-communi
30749 pts/0 00:00:15 gedit
30886 ?00:01:10 qtcreator.bin
30894 ?00:00:00 qtcreator.bin
31160 ?00:00:00 dhclient
31211 ?00:00:00 aptd
31302 ?00:00:00 sshd
31374 pts/2 00:00:00 bash
31397 pts/2 00:00:00 ps
范例3: 显示指定终端信息
root@localhost :~# ps -u root //显示终端1进程信息
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 watchdog/0
6 ?00:00:00 events/0
7 ?00:00:00 cpuset
8 ?00:00:00 khelper
9 ?00:00:00 netns
10 ?00:00:00 async/mgr
11 ?00:00:00 pm
12 ?00:00:00 sync_supers
13 ?00:00:00 bdi-default
14 ?00:00:00 kintegrityd/0
15 ?00:00:02 kblockd/0
16 ?00:00:00 kacpid
……省略部分结果
30487 ?00:00:06 gnome-terminal
30488 ?00:00:00 gnome-pty-helpe
30489 pts/0 00:00:00 bash
30670 ?00:00:00 debconf-communi
30749 pts/0 00:00:15 gedit
30886 ?00:01:10 qtcreator.bin
30894 ?00:00:00 qtcreator.bin
31160 ?00:00:00 dhclient
31211 ?00:00:00 aptd
31302 ?00:00:00 sshd
31374 pts/2 00:00:00 bash
31397 pts/2 00:00:00 ps
范例4: 显示所有进程信息,连同命令行
root@localhost :~# ps -ef //显示所有命令,连带命令行
UIDPID PPID C STIME TTY TIME CMD
root 1 0 0 10:22 ?00:00:02 /sbin/init
root 2 0 0 10:22 ?00:00:00 [kthreadd]
root 3 2 0 10:22 ?00:00:00 [migration/0]
root 4 2 0 10:22 ?00:00:00 [ksoftirqd/0]
root 5 2 0 10:22 ?00:00:00 [watchdog/0]
root 6 2 0 10:22 ?/usr/lib/NetworkManager
……省略部分结果
root 31302 2095 0 17:42 ?00:00:00 sshd: root@pts/2
root 31374 31302 0 17:42 pts/2 00:00:00 -bash
root 31400 1 0 17:46 ?00:00:00 /usr/bin/python /usr/sbin/aptd
root 31407 31374 0 17:48 pts/2 00:00:00 ps -ef
范例5: ps 与grep 常用组合用法,查找特定进程
root@localhost :~# ps -ef |grep sshd //查找字串为sshd的进程
root 2095 1 0 10:31 ?00:00:00 /usr/sbin/sshd
root 31302 2095 0 17:42 ?00:00:00 sshd: root@pts/2
root 31409 31374 0 17:50 pts/2 00:00:00 grep --color=auto sshd
root@localhost :~#
范例6: 显示命令的完整命令行
root@localhost :~# ps -efww
UIDPID PPID C STIME TTY TIME CMD
root 1 0 0 10:22 ?00:00:02 /sbin/init
root 2 0 0 10:22 ?00:00:00 [kthreadd]
root 3 2 0 10:22 ?00:00:00 [migration/0]
root 4 2 0 10:22 ?00:00:00 [ksoftirqd/0]
root 5 2 0 10:22 ?00:00:00 [watchdog/0]
root 6 2 0 10:22 ?00:00:00 [events/0]
……省略部分结果
root41 2 0 10:23 ?00:00:00 [kstriped]
root42 2 0 10:23 ?00:00:00 [kmpathd/0]
root43 2 0 10:23 ?00:00:00 [kmpath_handlerd]
root44 2 0 10:23 ?00:00:00 [ksnapd]
root45 2 0 10:23 ?00:00:00 [kondemand/0]
root46 2 0 10:23 ?00:00:00 [kconservative/0]
root233 2 0 10:23 ?00:00:00 [mpt_poll_0]
root234 2 0 10:23 ?00:00:00 [mpt/0]
root235 2 0 10:23 ?00:00:00 [scsi_eh_2]
root253 2 0 10:23 ?00:00:12 [jbd2/sda1-8]
root254 2 0 10:23 ?00:00:00 [ext4-dio-unwrit]
root314 1 0 10:23 ?00:00:00 upstart-udev-bridge --daemon
范例7: 显示进程间的关系
root@localhost :~# ps -efh
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
31374 pts/2 Ss 0:00 -bash USER=root LOGNAME=root HOME=/root PATH=/usr/local/sbin:/usr/
31418 pts/2 R+ 0:00 \_ ps -efh TERM=xterm SHELL=/bin/bash XDG_SESSION_COOKIE=93b5d3d0
30489 pts/0 Ss+ 0:00 bash XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg SPEECHD_PORT=6560
30749 pts/0 S 0:15 \_ gedit ui_mainlocalhost.h ORBIT_SOCKETDIR=/tmp/orbit-root SSH_AGENT
1025 tty7 Ss+ 10:12 /usr/bin/X :0 -nr -verbose -auth /var/run/gdm/auth-for-gdm-Ge8TFD/
1021 tty1 Ss+ 0:00 /sbin/getty -8 38400 tty1 PATH=/usr/local/sbin:/usr/local/bin:/usr
867 tty6 Ss+ 0:00 /sbin/getty -8 38400 tty6 PATH=/usr/local/sbin:/usr/local/bin:/usr
864 tty3 Ss+ 0:00 /sbin/getty -8 38400 tty3 PATH=/usr/local/sbin:/usr/local/bin:/usr
862 tty2 Ss+ 0:00 /sbin/getty -8 38400 tty2 PATH=/usr/local/sbin:/usr/local/bin:/usr
855 tty5 Ss+ 0:00 /sbin/getty -8 38400 tty5 PATH=/usr/local/sbin:/usr/local/bin:/usr
852 tty4 Ss+ 0:00 /sbin/getty -8 38400 tty4 PATH=/usr/local/sbin:/usr/local/bin:/usr
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)