How do I measure net used disk space change due to activity by a given process in Linux?

血红的双手。 提交于 2019-12-13 12:18:15

问题


I'd like to monitor disk space requirements of a running process. Ideally, I want to be able to point to a process and find out the net change in used disk space attributable to it. Is there an easy way of doing this in Linux? (I'm pretty sure it would be feasible, though maybe not very easy, to do this in Solaris with DTrace)


回答1:


Probably you'll have to ptrace it (or get strace to do it for you and parse the output), and then try to work out what disc is being used.

This is nontrivial, as your tracing process will need to understand which file operations use disc space - and be free of race conditions. However, you might be able to do an approximation.

Quite a lot of things can use up disc space, because most Linux filesystems support "holes". I suppose you could count holes as well for accounting purposes.

Another problem is knowing what filesystem operations free up disc space - for example, opening a file for writing may, in some cases, truncate it. This clearly frees up space. Likewise, renaming a file can free up space if it's renamed over an existing file.

Another issue is processes which invoke helper processes to do stuff - for example if myprog does a system("rm -rf somedir").

Also it's somewhat difficult to know when a file has been completely deleted, as it might be deleted from the filesystem but still open by another process.

Happy hacking :)




回答2:


If you know the PID of the process to monitor, you'll find plenty of information about it in /proc/<PID>.

The file /proc/<PID>/io contains statistics about bytes read and written by the process, it should be what you are seeking for.

Moreover, in /proc/<PID>/fd/ you'll find links to all the files opened by your process, so you could monitor them.




回答3:


there is Dtrace for linux is available

http://librenix.com/?inode=13584

Ashitosh



来源:https://stackoverflow.com/questions/4900758/how-do-i-measure-net-used-disk-space-change-due-to-activity-by-a-given-process-i

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