如何知道哪些应用程序在读取或写入文件 [英] How to know which application is reading or writing file

查看:243
本文介绍了如何知道哪些应用程序在读取或写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在方式Android或Android中NDK知道哪些应用程序读取或在磁盘或存储设备写入数据?

Is there any way in way in Android or in Android NDK to know which application is reading or writing data on disk or device memory?

推荐答案

我不知道是否有这样做,但Linux将允许您列出进程/打开的文件/插座,你可以尝试抓住事物的SDK方式从那里。

I don't know if there is a SDK way of doing it but Linux will allow you to list processes/open files/sockets and you can try grabbing things from there.

先使用ps命令来获得进程的PID,请输入:

First use ps command to get PID of process, enter:

$ ps -aef | grep {process-name}
$ ps -aef | grep httpd

接下来通过这个PID为pfiles将命令

Next pass this PID to pfiles command,

$ pfiles {PID}
$ pfile 3533

这是怎么你列出了Firefox中使用的所有打开的文件...

This is how you'd list all open files used by firefox...

lsof -p `ps -C firefox -o pid=`

您可以使用System.exec()来执行这些,但你也需要有root权限。这是一件好事,你必须要查看这方面的信息呢,我想...

You can use System.exec() to execute these, but you also need to have root access. Which is something you had to have to view that kind of information anyway I suppose...

编辑:

这是我从Py2Cmod了

this is what i got from Py2Cmod

INIT.C

/* Generated by py2cmod
*
* py2cmod (c) 2001 Mark Rowe
*/

#include "Python.h"

static PyObject *ErrorObject;

/* ----------------------------------------------------- */

/* List of methods defined in the module */

static struct PyMethodDef iotop/__init___methods[] = {

{NULL,   (PyCFunction)NULL, 0, NULL}        /* sentinel */
};


/* Initialization function for the module (*must* be called initiotop/__init__) */

static char iotop/__init___module_documentation[] =  "";

void initiotop/__init__()
{
PyObject *m, *d;

/* Create the module and add the functions */
m = Py_InitModule4("iotop/__init__", iotop/__init___methods,
    iotop/__init___module_documentation,
    (PyObject*)NULL,PYTHON_API_VERSION);

/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
ErrorObject = PyString_FromString("iotop/__init__.error");
PyDict_SetItemString(d, "error", ErrorObject);

/* XXXX Add constants here */
PyDict_SetItemString(d, "__file__", PyString_FromString("iotop/__init__.py"));
PyDict_SetItemString(d, "__name__", PyString_FromString("iotop/__init__"));


/* Check for errors */
if (PyErr_Occurred())
    Py_FatalError("can't initialize module iotop/__init__");
}

这篇关于如何知道哪些应用程序在读取或写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆