How can I see which CPU core a thread is running in?

前端 未结 7 1236
悲&欢浪女
悲&欢浪女 2020-12-07 14:09

In Linux, supposing a thread\'s pid is [pid], from the directory /proc/[pid] we can get many useful information. For example, these proc files, /proc/[pid]/status,/proc/[pid

7条回答
  •  失恋的感觉
    2020-12-07 14:27

    Accepted answer is not accurate. Here are the ways to find out which CPU is running the thread (or was the last one to run) at the moment of inquiry:

    1. Directly read /proc//task//stat. Before doing so, make sure format didn't change with latest kernel. Documentation is not always up to date, but at least you can try https://www.kernel.org/doc/Documentation/filesystems/proc.txt. As of this writing, it will be the 14th value from the end.
    2. Use ps. Either give it -F switch, or use output modifiers and add code PSR.
    3. Use top with Last Used Cpu column (hitting f gets you to column selection)
    4. Use htop with PROCESSOR column (hitting F2 gets you to setup screen)

提交回复
热议问题