Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14608
  • 博文数量: 8
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2017-08-14 14:17
文章分类
文章存档

2018年(2)

2017年(6)

我的朋友

分类: 系统运维

2017-08-25 14:35:34

1. 先启动一个ping程序持续输出到一个文件中

  1. [root@nicole-node1 ~]# ping 192.168.183.131 > ~/test.nicole &
  2. [1] 65694


2. lsof 显示下相关信息

  1. [root@nicole-node1 ~]# lsof ~/test.nicole
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. ping 65694 root 1w REG 8,3 565 71263587 /root/test.nicole

3. 删除输出的文件 

  1. [root@nicole-node1 ~]# rm ~/test.nicole
  2. rm: remove regular file ‘/root/test.nicole’? y

4. 再次显示打开的文件,表示无该文件


  1. [root@nicole-node1 ~]# lsof ~/test.nicole
  2. lsof: status error on /root/test.nicole: No such file or directory
  3. lsof 4.87
  4. latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
  5. latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
  6. latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
  7. usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
  8. [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
  9. [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
  10. Use the ``-h'' option to get more help information.

5. 通过ps 获取pid 65694

  1. [root@nicole-node1 ~]# ps auxww|grep -i ping
  2. zabbix 3008 0.0 0.2 260160 2420 ? S May24 0:06 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000006 sec, idle 5 sec]
  3. root 65694 0.0 0.0 114380 692 pts/0 S 07:38 0:00 ping 192.168.183.131
  4. root 65710 0.0 0.0 112648 972 pts/0 S+ 07:39 0:00 grep --color=auto -i ping
6.进入/proc/65694/fd,ls -l下可以看到fd与文件名的链接。


  1. [root@nicole-node1 65694]# cd /proc/65694/fd
  2. [root@nicole-node1 fd]# ls -l
  3. total 0
  4. lrwx------ 1 root root 64 May 27 07:38 0 -> /dev/pts/0
  5. l-wx------ 1 root root 64 May 27 07:38 1 -> /root/test.nicole (deleted)
  6. lrwx------ 1 root root 64 May 27 07:38 2 -> /dev/pts/0
  7. lrwx------ 1 root root 64 May 27 07:38 3 -> socket:[647220]

7. tail 对应的fd,这边是1,显示还在持续写入,将对应的文件拷出来,可以看到拷出来的文件不再写了。这点可以理解,毕竟cp后整个inode和block都与之前的不同了。

  1. [root@nicole-node1 fd]# cp 1 ~/.
  2. [root@nicole-node1 fd]# tail -f 1
  3. 64 bytes from 192.168.183.131: icmp_seq=85 ttl=64 time=0.401 ms
  4. 64 bytes from 192.168.183.131: icmp_seq=86 ttl=64 time=0.347 ms
  5. 64 bytes from 192.168.183.131: icmp_seq=87 ttl=64 time=0.334 ms
  6. 64 bytes from 192.168.183.131: icmp_seq=88 ttl=64 time=0.373 ms
  7. 64 bytes from 192.168.183.131: icmp_seq=89 ttl=64 time=0.311 ms
  8. 64 bytes from 192.168.183.131: icmp_seq=90 ttl=64 time=0.353 ms
  9. 64 bytes from 192.168.183.131: icmp_seq=91 ttl=64 time=0.444 ms
  10. 64 bytes from 192.168.183.131: icmp_seq=92 ttl=64 time=0.351 ms
  11. 64 bytes from 192.168.183.131: icmp_seq=93 ttl=64 time=0.308 ms
  12. 64 bytes from 192.168.183.131: icmp_seq=94 ttl=64 time=1.62 ms
  13. 64 bytes from 192.168.183.131: icmp_seq=95 ttl=64 time=0.204 ms
  14. 64 bytes from 192.168.183.131: icmp_seq=96 ttl=64 time=0.325 ms
  15. ^C
  16. [root@nicole-node1 fd]# ls ~/1
  17. /root/1
  18. [root@nicole-node1 fd]# tail ~/1
  19. 64 bytes from 192.168.183.131: icmp_seq=78 ttl=64 time=0.489 ms
  20. 64 bytes from 192.168.183.131: icmp_seq=79 ttl=64 time=0.244 ms
  21. 64 bytes from 192.168.183.131: icmp_seq=80 ttl=64 time=0.371 ms
  22. 64 bytes from 192.168.183.131: icmp_seq=81 ttl=64 time=0.263 ms
  23. 64 bytes from 192.168.183.131: icmp_seq=82 ttl=64 time=50.1 ms
  24. 64 bytes from 192.168.183.131: icmp_seq=83 ttl=64 time=0.426 ms
  25. 64 bytes from 192.168.183.131: icmp_seq=84 ttl=64 time=0.385 ms
  26. 64 bytes from 192.168.183.131: icmp_seq=85 ttl=64 time=0.401 ms
  27. 64 bytes from 192.168.183.131: icmp_seq=86 ttl=64 time=0.347 ms
  28. 64 bytes from 192.168.183.131: icmp_seq=87 ttl=64 time=0.334 ms

8. kill 进程后,这个fd就没有了。

  1. [root@nicole-node1 fd]# cp 1 ~/nicole.test && kill 65694
  2. [root@nicole-node1 fd]# ls
  3. [1]+ Terminated ping 192.168.183.131 > ~/test.nicole (wd: ~)
  4. (wd now: /proc/65694/fd)
  5. [root@nicole-node1 fd]# ls



阅读(819) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~