linux - 一个线程的自愿_ctxt_switches怎么会减少呢?
问题描述
我尝试使用以下脚本获取线程的上下文切换:
text=`cat /proc/$pid/task/$tid/sched | grep voluntary_switches`
ts=`date +%s%3N`
vol=`echo "$text" | grep nr_vol | cut -d':' -f2 | awk '{$1=$1};1'`
non_vol=`echo "$text" | grep nr_invol | cut -d':' -f2 | awk '{$1=$1};1'`
echo "$tid,$ts,$vol,$non_vol"
我可以得到一个由 4 列组成的输出,它们是
- 线程 ID
- 以毫秒为单位的时间戳
- 自愿的_ctxt_switches
- 非自愿_ctxt_switches
我运行脚本 5 次,得到了第 2、3、4 轮的结果:
<tid>,1531390066833,10,0
<tid>,1531390082618,10,0
<tid>,1531390098127,7,0
如您所见,timestamp 不断增加,但 voluntainty_ctxt_switches 减少了。
我不明白这怎么会发生,因为 自愿性_ctxt_switches 是一个累积计数器。
解决方案
推荐阅读
- python - 在 for 循环中迭代时如何更改 tkinter 中每个输入框的名称?
- javascript - 不和谐 | 我如何使用 ID 来制作化身命令,不仅提到
- flutter - 为什么showcaseview在第一次尝试时会抛出错误?
- docker - Kafka Schema Registry 无法注册 Schema - 由于 master 未知,注册模式请求失败
- python - QTextTable 在单元格中插入一行
- java - 使用 Keytool 的 Java HTTPS 服务器
- python - 错误消息说我的目录有语法错误
- python - 如何将线程用于拥抱面变压器
- javascript - 发送 res.status.send() 后 Firebase 调用仍在执行
- java - 来自Android中不同类的setContentView(R.layout.xy)