加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何定时查询某线程的CPU执行时间

发布时间:2020-12-13 23:43:02 所属栏目:Linux 来源:网络整理
导读:? ? 1 #!/bin/ bash 2 3 pid=$( ps -T -p $(pgrep xxx) | grep xxx | gawk -F " " ‘ {print $2} ‘ ) 4 if [ -z $pid ]; then 5 echo " can not find xxx " 6 exit 1 7 fi 8 echo " pid: " $pid 9 prev_runtime= 0 10 while true ; do 11 current_runtime=`

?

?

 1 #!/bin/bash
 2 
 3 pid=$(ps -T -p $(pgrep xxx) | grep xxx | gawk -F" " {print $2})
 4 if [ -z $pid ]; then
 5   echo "can not find xxx"
 6   exit 1
 7 fi
 8 echo "pid: "$pid
 9 prev_runtime=0
10 while true; do 
11   current_runtime=`cat /proc/$pid/sched | grep exec_run | gawk -F: {print $2} | gawk -F"." {print $1}`;  
12   #echo $current_runtime
13   delta=$(expr $current_runtime - $prev_runtime)
14   echo "rtime:$delta ms/s"
15   prev_runtime=$current_runtime
16   sleep 1; 
17 done

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读