gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:48 25 4
gpt4 key购买 nike

我试图监控子进程的内存使用峰值。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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com