1

I am currently creating a program which identifies processes which are hung/out-of-control, and using an entire CPU core. The program then terminates them, so the CPU usage can be kept under control. These are all single-threaded processes.

However, I have run into a problem: When I execute the 'tasklist' command on Windows, it outputs this:


Image Name:   Blockland.exe
PID:          4880
Session Name: Console
Session#:     6
Mem Usage:    127,544 K
Status:       Running
User Name:    [removed]\[removed]
CPU Time:     0:00:22
Window Title: C:\HammerHost\Blockland\Blockland.exe

So I know that the line which says "CPU Time" is an indication of the total time, in seconds, used by the program ever since it started.

But let's suppose there are 4 CPU cores on the system. Does this mean that it used up 22 seconds of one core, and therefore used 5.5 seconds on the entire CPU in total? Or does this mean that the process used up 22 seconds on the entire CPU?

1

The "CPU time" is the total time used by the program on all CPUs ("CPU" here means "core" if you have hyperthreading disabled; it means "logical processor", if you have hyperthreading enabled).

Thus on a system with four cores, HT disabled, a program that runs for 30 seconds of wall-clock time could theoretically use up to 120 seconds of CPU time.

As MaQleod stated, a single thread will only ever run on one CPU at a time. However single-threaded programs are fairly rare these days.

Does this mean that it used up 22 seconds of one core, and therefore used 5.5 seconds on the entire CPU in total? Or does this mean that the process used up 22 seconds on the entire CPU?

It could be 22 seconds on one core. It could mean 5.5 seconds on each of four cores, all at the same time, which could be described as "5.5 seconds on the entire CPU". Or it could be 5 seconds on one core, 2 on another, 15 on a third, and nothing on the fourth core.

Or the 22 seconds total CPU time could have been spread over much more wall-clock time, with a lot of waiting. Most programs spend most of their time waiting. A more useful metric than total CPU time used is percentage CPU time used. But it's very tricky to truly identify CPU hogs, as opposed to programs that are just momentarily compute-bound. Terminating a process can lose work and even corrupt files - are you sure you want to do that?

Hint: Don't try to terminate the idle process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.