How to know the exact location where the file is being accessed in Android NDK

a 夏天 提交于 2020-01-16 19:07:27

问题


With "lsof" i can check the list of open files is there any command or any other way by which i can detect where the files the files are being accessed. The output of "lsof" command is as follows:-

COMMAND     PID       USER   FD      TYPE             DEVICE  SIZE/OFF       NODE NAME

init          1        ???  cwd       ???                ???       ???        ??? /proc/1/cwd (readlink: Permission denied)

init          1        ???  exe       ???                ???       ???        ??? /proc/1/exe (readlink: Permission denied)

init          1        ??? root       ???                ???       ???        ??? /proc/1/root (readlink: Permission denied)

init          1        ???  FDS                                                   /proc/1/fd/ (opendir: Permission denied)

init          2        ???  cwd       ???                ???       ???        ??? /proc/2/cwd (readlink: Permission denied)

init          2        ???  exe       ???                ???       ???        ??? /proc/2/exe (readlink: Permission denied)

init          2        ??? root       ???                ???       ???        ??? /proc/2/root (readlink: Permission denied)

init          2        ???  FDS                                                   /proc/2/fd/ (opendir: Permission denied)

init          3        ???  cwd       ???                ???       ???        ??? /proc/3/cwd (readlink: Permission denied)

init          3        ???  exe       ???                ???       ???        ??? /proc/3/exe (readlink: Permission denied)

init          3        ??? root       ???                ???       ???        ??? /proc/3/root (readlink: Permission denied)

init          3        ???  FDS                                                   /proc/3/fd/ (opendir: Permission denied)

init          4        ???  cwd       ???                ???       ???        ??? /proc/4/cwd (readlink: Permission denied)

init          4        ???  exe       ???                ???       ???        ??? /proc/4/exe (readlink: Permission denied)

init          4        ??? root       ???                ???       ???        ??? /proc/4/root (readlink: Permission denied)

init          4        ???  FDS                                                   /proc/4/fd/ (opendir: Permission denied)

init          5        ???  cwd       ???                ???       ???        ??? /proc/5/cwd (readlink: Permission denied)

init          5        ???  exe       ???                ???       ???        ??? /proc/5/exe (readlink: Permission denied)

init          5        ??? root       ???                ???       ???        ??? /proc/5/root (readlink: Permission denied)

init          5        ???  FDS                                                   /proc/5/fd/ (opendir: Permission denied)

init          6        ???  cwd       ???                ???       ???        ??? /proc/6/cwd (readlink: Permission denied)

init          6        ???  exe       ???                ???       ???        ??? /proc/6/exe (readlink: Permission denied)

init          6        ??? root       ???                ???       ???        ??? /proc/6/root (readlink: Permission denied)

init          6        ???  FDS                                                   /proc/6/fd/ (opendir: Permission denied)

init          7        ???  cwd       ???                ???       ???        ??? /proc/7/cwd (readlink: Permission denied)

init          7        ???  exe       ???                ???       ???        ??? /proc/7/exe (readlink: Permission denied)

init          7        ??? root       ???                ???       ???        ??? /proc/7/root (readlink: Permission denied)

init          7        ???  FDS                                                   /proc/7/fd/ (opendir: Permission denied)

init          8        ???  cwd       ???                ???       ???        ??? /proc/8/cwd (readlink: Permission denied)

init          8        ???  exe       ???                ???       ???        ??? /proc/8/exe (readlink: Permission denied)

init          8        ??? root       ???                ???       ???        ??? /proc/8/root (readlink: Permission denied)

init          8        ???  FDS                                                   /proc/8/fd/ (opendir: Permission denied)

init          9        ???  cwd       ???                ???       ???        ??? /proc/9/cwd (readlink: Permission denied)

init          9        ???  exe       ???                ???       ???        ??? /proc/9/exe (readlink: Permission denied)

init          9        ??? root       ???                ???       ???        ??? /proc/9/root (readlink: Permission denied)

init          9        ???  FDS                                                   /proc/9/fd/ (opendir: Permission denied)

init         10        ???  cwd       ???                ???       ???        ??? /proc/10/cwd (readlink: Permission denied)

For each pid i am getting three locations like for pid "9" i am getting the following locations:- "/proc/1/cwd (readlink: Permission denied)","/proc/9/exe","/proc/9/fd/ (opendir: Permission denied)"

Now how can i know which file is exactly being used? I am a newbie so don't know enough.Any suggestion would be a great help from your side.


回答1:


Try fuser. http://linux.die.net/man/1/fuser It is used to identify processes using files or sockets.



来源:https://stackoverflow.com/questions/12347201/how-to-know-the-exact-location-where-the-file-is-being-accessed-in-android-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!