如何测量由于Linux中给定进程的活动而导致的净磁盘使用空间变化? [英] How do I measure net used disk space change due to activity by a given process in Linux?

查看:75
本文介绍了如何测量由于Linux中给定进程的活动而导致的净磁盘使用空间变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视正在运行的进程的磁盘空间需求.理想情况下,我希望能够指向一个进程并找出可归因于此的已用磁盘空间的净变化.在Linux中有一种简单的方法吗? (我敢肯定,在Solaris中使用DTrace做到这一点是可行的,尽管可能不是很容易)

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)

推荐答案

可能您必须对其进行ptrace(或使用strace为您完成并解析输出),然后尝试找出正在播放的光盘使用.

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.

很多事情都会消耗磁盘空间,因为大多数Linux文件系统都支持漏洞".我想您出于会计目的也可以算空洞.

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.

另一个问题是调用辅助进程进行处理的进程-例如,如果myprog执行系统("rm -rf somedir").

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.

快乐黑客:)

这篇关于如何测量由于Linux中给定进程的活动而导致的净磁盘使用空间变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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