更具体地说,这是我的用例:
有一个进程等待用户执行程序的请求.为了执行这些程序,这个过程调用子进程(一次最多限制为5个)&每个子进程执行其中一个提交的程序(假设用户一次提交了15个程序).因此,如果用户提交了15个程序,那么将运行3批5个子进程.子进程在完成程序执行后立即被终止.
我想知道在执行这15个程序期间父进程及其所有子进程的%cpu利用率.
使用top或其他命令有没有简单的方法呢? (或者我应该附加到父进程的任何工具.)
解决方法 您可以在/ proc / PID / stat中找到此信息,其中PID是您父进程的进程ID.假设父进程等待其子进程,则可以从utime,stime,cutime和cstime计算总cpu使用率:utime %lu
Amount of time that this process has been scheduled in user mode,
measured in clock ticks (divIDe by sysconf(_SC_CLK_TCK). This includes
guest time,guest_time (time spent running a virtual cpu,see below),
so that applications that are not aware of the guest time fIEld do not
lose that time from their calculations.stime %lu
Amount of time that this process has been scheduled in kernel mode,
measured in clock ticks (divIDe by sysconf(_SC_CLK_TCK).cutime %ld
Amount of time that this process’s waited-for children have been
scheduled in user mode,measured in clock ticks (divIDe by
sysconf(_SC_CLK_TCK). (See also times(2).) This includes guest time,
cguest_time (time spent running a virtual cpu,see below).cstime %ld
Amount of time that this process’s waited-for children have been
scheduled in kernel mode,measured in clock ticks (divIDe by
sysconf(_SC_CLK_TCK).
有关详情,请参见proc(5) manpage.
总结以上是内存溢出为你收集整理的如何在Linux中计算进程及其所有子进程的CPU利用率?全部内容,希望文章能够帮你解决如何在Linux中计算进程及其所有子进程的CPU利用率?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)