[英]Is there any alterntive to wait3 to get rusage structure in shell scripting?
我试图监视子进程的峰值内存使用情况。时间-v是一个选项,但它在solaris中不起作用。那么有没有办法从shell脚本获取rusage结构中的细节?
You can use /usr/bin/timex
您可以使用/usr/bin/timex
From the /usr/bin/timex
man page : 从/usr/bin/timex
手册页 :
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. -p列出命令及其所有子项的进程记帐记录。 This option works only if the process accounting software is installed. 此选项仅在安装了进程记帐软件时有效。 Suboptions f, h, k, m, r, and t modify the data items reported. 子选项f,h,k,m,r和t修改报告的数据项。 The options are as follows: 选项如下:
... ...
Start with the man page for acctadm
to get process accounting enabled. 从acctadm
的手册页开始,以启用进程记帐。
Note that on Solaris, getrusage()
and wait3()
do not return memory usage statistics. 请注意,在Solaris上, getrusage()
和wait3()
不返回内存使用情况统计信息。 See the (somewhat dated) getrusage()
source code at http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/syscall/rusagesys.c and the wait3()
source code at http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/sys/common/wait.c#158 (That's actually OpenSolaris source, which Oracle dropped support for, and it may not represent the current Solaris implementation, although a few tests on Solaris 11.2 show that the RSS data is in fact still zero.) 请参阅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 11.2上的一些测试表明RSS数据实际上仍为零,但它可能并不代表当前的Solaris实现。)
Also, from the Solaris getrusage()
man page : 另外,从Solaris getrusage()
手册页 :
The
ru_maxrss
,ru_ixrss
,ru_idrss
, andru_isrss
members of therusage
structure are set to 0 in this implementation. 在此实现中,rusage
结构的ru_maxrss
,ru_ixrss
,ru_idrss
和ru_isrss
成员被设置为0。
There are almost certainly other ways to get the data, such as dtrace
. 几乎可以肯定有其他方法来获取数据,例如dtrace
。
Edit: 编辑:
dtrace
doesn't look to be much help, unfortunately. 不幸的是, dtrace
并没有太大的帮助。 Attempting to run this dtrace
script with dtrace -s memuse.d -c bash
尝试使用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 );
}
resulted in the following error message: 导致以下错误消息:
dtrace: failed to compile script memuse.d: line 8: translator does not define conversion for member: pr_pctmem
dtrace
on Solaris doesn't appear to provide access to process memory usage. Solaris上的dtrace
似乎不提供对进程内存使用的访问。 In fact, the Solaris 11.2 /usr/lib/dtrace/procfs.d
translator for procfs
data has this comment in it: 实际上, 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.
*/
Browsing the Illumos.org source code, searching for ps_rssize
, indicates that the procfs
data is computed only when needed, and not updated continually as the process runs. 浏览Illumos.org源代码,搜索ps_rssize
,表示procfs
数据仅在需要时计算,并且在进程运行时不会持续更新。 (See http://src.illumos.org/source/search?q=pr_rssize&defs=&refs=&path=&hist=&project=illumos-gate ) (参见http://src.illumos.org/source/search?q=pr_rssize&defs=&refs=&path=&hist=&project=illumos-gate )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.