免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5660 | 回复: 2
打印 上一主题 下一主题

[高级应用] aix内核如何通过fd获取文件全路径? [复制链接]

论坛徽章:
2
技术图书徽章
日期:2014-04-23 10:23:38射手座
日期:2014-08-14 17:00:52
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-03-20 17:12 |只看该作者 |倒序浏览

RT,在aix内核扩展中,已知进程pid和这个进程打开文件的fd,如何知道这个文件的全路径呢?

论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-11-09 06:20:00
2 [报告]
发表于 2014-04-04 15:28 |只看该作者
under /proc/pid$$$/fd you can see the real files that have been opened by the process.
Use procfiles pid$$$,part of the output will like "dev:10,5",then you can use command ls -l /dev/ | grep "10, *5",
# ls -l | grep "10, *5"                                                
brw-rw----   1 root     system       10,  5 Oct 10 2005  hd2           
crw-rw----   1 root     system       10,  5 Oct 10 2005  rhd2         
                                                                       
So the device or logical volume that contains the file system in this example is /dev/hd2.
                                                
# lsfs | grep hd2                                                      
/dev/hd2        --         /usr                   jfs2  3801088 --     
yes  no                                                               
                                                                       
This filesystem is mounted at /usr.                                    
                                                                       
We can use the following command to obtain information about the file with file descriptor 4 and inode 13407.                              
                                                                       
# istat 13407 /usr                                                     
Inode 13407 on device 10/5      File                                   
Protection: rw-r--r--                                                  
Owner: 2(bin)           Group: 2(bin)                                 
Link count:   1         Length 4811 bytes                              
                                                                       
Last updated:   Tue Aug 24 16:14:48 CDT 2004                           
Last modified:  Mon Jul 12 11:33:31 CDT 2004                           
Last accessed:  Wed Aug  9 09:16:28 CDT 2006                           
                                                                       
Block pointers (hexadecimal):                                          
1892c                                                                  

We can use this find command to find all file names in the filesystem /usr with an inode of 13407.
                              
# cd /usr                                                              
# find . -inum 13407 -exec ls -l {} \;                                 
-rw-r--r--   1 bin      bin            4811 Jul 12 2004            
./lib/nls/msg/en_US/hostmibd.cat                    

评分

参与人数 1可用积分 +10 信誉积分 +2 收起 理由
hello_unix + 10 + 2 赞一个!

查看全部评分

论坛徽章:
2
技术图书徽章
日期:2014-04-23 10:23:38射手座
日期:2014-08-14 17:00:52
3 [报告]
发表于 2014-04-23 10:23 |只看该作者
这个好像是用户态获取把,如何在内核扩展中获取呢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP