转自:https://www.linuxidc.com/Linux/2017-06/144975.htm
lsof 命令用法:查看已删除空间却没有释放的进程
查看已经删除的文件,空间有没有释放,没有的话kill掉pid
lsof -n |grep deleted
lsof简介lsof(list open files)是一个列出当前系统打开文件的工具。
问题描述:
服务报警根分区使用率超过95%,上来查看发现96%使用率;
但是/分区下面的目录,每个查询加起来也不到4G空间,多出来的40G不知道在哪里?
find查询也没有找到大文件;
分析原因:
可能是系统进程占用的空间没有释放掉,导致的;
通过命令查看发现,php进程一共有3个,都是处于deleted状态,文件大小刚好是40G,正好是多出来的空间,找到问题所在;
解决办法:
找到对应的php进程号,kill掉即可;
[[email protected] WebServer]# lsof -n / |grep deleted
mysqld 2660 mysql 4u REG 8,2 0 524290 /tmp/ibSF7sXt (deleted)
mysqld 2660 mysql 5u REG 8,2 0 524305 /tmp/ibCCM4u4 (deleted)
mysqld 2660 mysql 6u REG 8,2 0 524309 /tmp/ibKuAG2E (deleted)
mysqld 2660 mysql 7u REG 8,2 0 524315 /tmp/ibcLe4Bf (deleted)
mysqld 2660 mysql 11u REG 8,2 0 524316 /tmp/ibW2n1iQ (deleted)
php 7045 root 0r REG 8,2 1172 524374 /tmp/sh-thd-1494029191 (deleted)
php 7045 root 2w REG 8,2 42413952626 657428 /var/spool/at/spool/a0100c017bf37c (deleted)
php 7054 root 0r REG 8,2 1172 524374 /tmp/sh-thd-1494029191 (deleted)
php 7054 root 2w REG 8,2 42413952626 657428 /var/spool/at/spool/a0100c017bf37c (deleted)
php 12730 root 0r REG 8,2 1172 524374 /tmp/sh-thd-1494029191 (deleted)
php 12730 root 2w REG 8,2 42413952626 657428 /var/spool/at/spool/a0100c017bf37c (deleted)
mysqld 17855 mysql 4u REG 8,2 0 524384 /tmp/ibxBS5jf (deleted)
mysqld 17855 mysql 5u REG 8,2 0 524385 /tmp/ibmrNzfL (deleted)
mysqld 17855 mysql 6u REG 8,2 0 524386 /tmp/ibVDS3ah (deleted)
mysqld 17855 mysql 7u REG 8,2 0 524387 /tmp/ibx6YTrj (deleted)
mysqld 17855 mysql 13u REG 8,2 0 524388 /tmp/ibOhb8xQ (deleted)
在对应的目录下并没有发现文件
[[email protected] WebServer]# ll /var/spool/at/spool/
总用量 0
[[email protected] WebServer]# kill -9 7045
[[email protected] WebServer]# kill -9 7054
[[email protected] WebServer]# kill -9 12730
再次查看发现没有php的进程
[[email protected] WebServer]# lsof -n / |grep deleted
mysqld 2660 mysql 4u REG 8,2 0 524290 /tmp/ibSF7sXt (deleted)
mysqld 2660 mysql 5u REG 8,2 0 524305 /tmp/ibCCM4u4 (deleted)
mysqld 2660 mysql 6u REG 8,2 0 524309 /tmp/ibKuAG2E (deleted)
mysqld 2660 mysql 7u REG 8,2 0 524315 /tmp/ibcLe4Bf (deleted)
mysqld 2660 mysql 11u REG 8,2 0 524316 /tmp/ibW2n1iQ (deleted)
mysqld 17855 mysql 4u REG 8,2 0 524384 /tmp/ibxBS5jf (deleted)
mysqld 17855 mysql 5u REG 8,2 0 524385 /tmp/ibmrNzfL (deleted)
mysqld 17855 mysql 6u REG 8,2 0 524386 /tmp/ibVDS3ah (deleted)
mysqld 17855 mysql 7u REG 8,2 0 524387 /tmp/ibx6YTrj (deleted)
mysqld 17855 mysql 13u REG 8,2 0 524388 /tmp/ibOhb8xQ (deleted)
查看空间已经恢复:
[[email protected] WebtServer]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda2 49G 4.4G 42G 10% /
tmpfs 16G 0 16G 0% /dev/shm