linux - 是否有 wait3 的替代方法来在 shell 脚本中获取 usage 结构?

标签 linux time solaris rusage

我试图监控子进程的内存使用峰值。time -v 是一个选项,但它在 solaris 中不起作用。那么有什么方法可以从 shell 脚本中获取 usage 结构中的详细信息?

最佳答案

你可以使用/usr/bin/timex

来自 the /usr/bin/timex man page :

The given command is executed; the elapsed time, user time and system time spent in execution are reported in seconds. Optionally, process accounting data for the command and all its children can be listed or summarized, and total system activity during the execution interval can be reported.

...

-p List process accounting records for command and all its children. This option works only if the process accounting software is installed. Suboptions f, h, k, m, r, and t modify the data items reported. The options are as follows:

...

acctadm 的手册页开始启用进程记帐。

请注意,在 Solaris 上,getrusage()wait3() 不返回内存使用统计信息。在 http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/syscall/rusagesys.c 查看(有点过时的)getrusage() 源代码和 wait3() 源代码位于 http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/sys/common/wait.c#158 (这实际上是 OpenSolaris 源,Oracle 放弃了对它的支持,它可能不代表当前的 Solaris 实现,尽管对 Solaris 11.2 的一些测试表明 RSS 数据实际上仍然为零。)

此外,来自 Solaris getrusage() man page :

The ru_maxrss, ru_ixrss, ru_idrss, and ru_isrss members of the rusage structure are set to 0 in this implementation.

几乎可以肯定还有其他方法可以获取数据,例如 dtrace

编辑:

不幸的是,

dtrace 看起来没什么用。尝试使用 dtrace -s memuse.d -c bash

运行此 dtrace 脚本
#!/usr/sbin/dtrace -s

#pragma D option quiet

profile:::profile-1001hz
/ pid == $target /
{
    @pct[ pid ] = max( curpsinfo->pr_pctmem );
}

dtrace:::END
{
    printa( "pct: %@u %a\n", @pct );
}

导致以下错误消息:

dtrace: failed to compile script memuse.d: line 8: translator does not define conversion for member: pr_pctmem
Solaris 上的

dtrace 似乎不提供对进程内存使用情况的访问。事实上,procfs 数据的 Solaris 11.2 /usr/lib/dtrace/procfs.d 转换器中有这样的注释:

/*
 * Translate from the kernel's proc_t structure to a proc(4) psinfo_t struct.
 * We do not provide support for pr_size, pr_rssize, pr_pctcpu, and pr_pctmem.
 * We also do not fill in pr_lwp (the lwpsinfo_t for the representative LWP)
 * because we do not have the ability to select and stop any representative.
 * Also, for the moment, pr_wstat, pr_time, and pr_ctime are not supported,
 * but these could be supported by DTrace in the future using subroutines.
 * Note that any member added to this translator should also be added to the
 * kthread_t-to-psinfo_t translator, below.
 */

浏览 Illumos.org 源代码,搜索 ps_rssize,表明 procfs 数据仅在需要时计算,并且不会随着进程运行而不断更新。 (参见 http://src.illumos.org/source/search?q=pr_rssize&defs=&refs=&path=&hist=&project=illumos-gate)

关于linux - 是否有 wait3 的替代方法来在 shell 脚本中获取 usage 结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38735793/

相关文章:

linux - 如何让 Linux Mint 17、打印服务器 TP-LInk TL-PS110U 和热敏打印机 Asterix ST-EP4 一起工作?

linux - 在 Pycharm 中修改我的 Python 代码后,如何将更改部署到我的 Portainer?

PHP日期和时间问题

excel - 在 EXCEL 中如何将 J2000 时间值转换为标准日期和军事时间?

c++ - unix下单进程 "top"命令计算Cpu百分比

c - 运行 Linux 守护进程与后台无限循环

python 子进程输出被截断

iphone - 获得精确的时间戳和时间差异

process - 如何使用 dtrace 显示每个进程消耗的微秒 cpu?

java - JVM 在 Solaris 机器中崩溃 有问题的帧 : # C [libc. so.1]# [ 计时器已过期,中止...]