如何将 S-output-modifier 与 Unix/Linux 命令 ps 一起使用?
该命令
ps -o time -p 21361
有效;但是我需要的是进程的运行时间,包括所有 孩子们。例如,如果21361是一个bash脚本,它调用其他脚本, 然后我想要总的运行时间,包括所有孩子的运行时间。
现在 ps 文档列出了“OUTPUT MODIFIER”:
S
Sum up some information, such as CPU usage, from dead child processes into their parent. This is useful for examining a system where a parent process repeatedly forks off short-lived children to do work.
听起来不错。不幸的是,没有 ps 语法的规范,所以 我不知道把“S”放在哪里!几个小时以来我尝试了很多组合,但是 要么我得到语法错误,要么“S”什么也没做。在互联网上你只能找到 关于 ps 的非常基本的信息(并且始终相同),特别是“S”修饰符 我找不到任何地方提到过,也没有人解释过 ps 的语法。
The command
ps -o time -p 21361
works; however what I need is the running time of the process including all
the children. For example, if 21361 is a bash script, which calls other scripts,
then I want the total running time, including the running time of all children.
Now the ps documentation lists the "OUTPUT MODIFIER":
S
Sum up some information, such as CPU usage, from dead child processes into their parent. This is useful for examining a system where a parent process repeatedly forks off short-lived children to do work.
Sounds just right. Unfortunately, there is no specification of the ps-syntax, so
I have no clue where to place the "S"! For hours now I tried many combinations, but
either I get syntax errors, or "S" makes nothing. And on the Internet you find only
very basic information about ps (and always the same), specifically the "S" modifier
I couldn't find mentioned anywhere, and also nobody ever explains the syntax of ps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定,但 ps 在这方面可能有些问题。在这里尝试一下:
这是使用 ps 的 BSD 选项。它可以在我的机器上运行,但是您会得到额外的标题行和额外的列。我会使用 tr 和 cut 将它们切掉:
I am not sure, but it might be that ps is somewhat buggy in this respect. Try this here:
This is using the BSD options for ps. It works on my machine, however you get an extra header row and extra columns. I would cut them away using tr and cut:
在 MacOS X(10.7,Lion)上,手册页显示:
因此,我能够使用以下方式获得输出:
但是,该输出与省略 '
-S
' 选项时实际上没有任何不同。我尝试过:
如您所见,将
/dev/zero
复制到/dev/null
所花费的 15 秒系统时间并未包含在摘要中。在这个阶段,弄清楚“
-S
”选项的作用的唯一方法(如果有的话)就是查看源代码。您可以在 FreeBSD 版本中查找sumrusage
,例如,在 FreeBSD。On MacOS X (10.7, Lion) the manual page says:
So, I was able to get output using:
However, that output was not really any different from when the '
-S
' option was omitted.I tried:
As you can see, the 15 seconds of system time spent copying
/dev/zero
to/dev/null
did not get included in the summary.At this stage, the only way of working out what the '
-S
' option does, if anything, is to look at the source. You could look forsumrusage
in the FreeBSD version, for example, at FreeBSD.