根据打开文件句柄查找文件

时间:2021-11-11 21:29:58
[oracle@june2 ~]$ vi 1.sh

while :
do
sqlplus scott/oracle<<!
select seq1.nextval from dual;
exit
!
done
~

通过lsof 查看打开文件的进程
[root@june2 fd]# lsof | grep 1.sh
vim 6665 oracle 4u REG 3,3 12288 5200006 /oracle/.1.sh.swp


打开程序为vim 进程为6665 文件描述符为4

[root@june2 ~]# cd /proc/
[root@june2 proc]# ls
1 1671 1843 2086 2281 2379 346 6215 77 execdomains loadavg stat
10 1673 1885 2087 2295 2381 347 6424 79 fb locks swaps
11 1698 1906 2094 2297 2383 348 6470 8 filesystems mdstat sys
1278 17 1927 2100 2307 2385 358 6472 9 fs meminfo sysrq-trigger
1279 1701 1947 2108 2357 2387 371 6473 acpi ide misc sysvipc
1280 1713 1958 2171 2359 2389 399 6512 buddyinfo interrupts modules tty
1310 1726 1963 2174 2363 2391 4 6547 bus iomem mounts uptime
147 1751 1978 2175 2365 2403 433 6548 cmdline ioports mtrr version
148 1777 1989 2182 2367 2419 4545 6615 cpuinfo irq net vmcore
149 1778 2 2188 2369 2421 4564 6665 crypto kallsyms partitions vmstat
15 1786 2020 2189 2371 2423 5 6673 devices kcore schedstat zoneinfo
150 1805 2041 2190 2373 2463 6 7 diskstats keys scsi
151 1816 2074 2278 2375 3 6105 73 dma key-users self
16 1822 2075 2280 2377 309 6109 74 driver kmsg slabinfo

[root@june2 proc]# cd 6665
[root@june2 6665]# cd fd
[root@june2 fd]# ls
0 1 2 4
[root@june2 fd]# cat 4
3210#"! Utp