Determine which CPU a process is running on

19

3

Using Sysinternals' Process Explorer, is there a column that can be used to indicate which CPU a process is running on? If no column, is there some other way?

rory.ap

Posted 2015-01-20T14:12:29.817

Reputation: 433

1

possible duplicate of How do I see a log of which process was running on which CPU and for how long?

– DavidPostill – 2015-01-20T14:36:54.990

3@DavidPostill -- The best answer just points to Process Explorer's web page. My question is: given process explorer, how to I determine which core a process is started on? – rory.ap – 2015-01-20T14:38:42.897

Answers

47

Requested in 2005:

I am very impressed with the features integrated in Process Explorer but would like to see an option to display each process CPU affinity in the main window as a column toggle.

No response.

Requested in 2007:

Thanks for superb utilities. My request is to add a column option to process explorer to display CPU affinity. That's it.

No response.

Similar discussed in 2013:

It would be really nice if there were a new Process Performance View Column called Core Usage that would show a sum of the usage over the core that the process is running on.

Basic synopsis: It can't be done.

Threads are what are sent to cores for processing, not processes. Most modern processes have multiple threads.

If you manually set the affinity for a process, then all threads for the process should stick to a single processor. Since you manually set it, you should know which CPU it's on. ;)

But if you don't specify, then the thread(s) will be controlled by the OS and underlying processing hardware, and would jump around between processors at a speed that would be unwatchable, and very likely inaccurate by the time it was displayed to you.

Perhaps check out these SU question for more:

Also, from StackOverflow:

Now if you wrote the program, you could use the GetCurrentProcessorNumber, which reports the current processor in use by the thread from which the function was called.

Using this will allow you to make estimations about processor usage by your threads, as you can never be sure where the threads will be one cycle to the next (again, unless you set the affinity on purpose).

More info:

Ƭᴇcʜιᴇ007

Posted 2015-01-20T14:12:29.817

Reputation: 103 763

3Nice answer ... :) – DavidPostill – 2015-01-20T14:50:00.813

@DavidPostill -- Agreed. – rory.ap – 2015-01-20T14:53:07.820

Great answer, as it answers the specific question, gets into the history and whys, and helps to understand the concepts. – Smithers – 2015-01-20T18:07:13.537

1On both Linux and Windows it's possible to set the affinity on a per-thread basis. However, this is rarely ever useful, therefore rarely ever done, therefore displaying a per-thread affinity in a generic monitoring program if it is set is more-or-less useless - the vast majority would just let the kernel schedule as it pleases. – Bob – 2015-01-20T22:42:23.123

The OS could even switch your thread to another processor just after GetCurrentProcessorNumber is called (but before it starts executing) and again just after it returns, so the result would be neither the processor at the time of the call, nor the processor at the time the call returns! – gnasher729 – 2015-01-21T19:07:26.453

8

This can be done by capturing a xperf trace and opening it with Windows Performance Analyzer (WPA.exe) from the Windows Performance Toolkit, here you can add a column CPU to see which CPU (Core) the process is running:

enter image description here

magicandre1981

Posted 2015-01-20T14:12:29.817

Reputation: 86 560

Nice. Does it list the same process under each CPU (if it's using more than one)? Since it's using a captured xperf trace, does that mean it's not live reporting? – Ƭᴇcʜιᴇ007 – 2015-01-21T13:39:16.180

@Ƭᴇcʜιᴇ007 ETW events can be also consumed at runtime. Writing them into a ETL file is just one way. Yes, it lists processes under both CPU when it uses both. – magicandre1981 – 2015-01-21T16:29:36.577