Really odd question I know. It's to help demonstrate my university coursework. I'm going to be killing processes that are using more than 10% of the CPU.
1 Answer
I wrote the following super-simple C program some time ago to test scheduling algorithms, should work for you as well:
#include <stdio.h>
#include <stdlib.h>
void main()
{
while(1==1)
{
int a = 400;
a * 400;
}
}
Compile with gcc -o executable_name c_source_file.c
and run with ./executable_name
. This should give you a single process with 100% cpu usage.
-
Note: this would be a single thread, therefore at most it can use 100% of a single logical core. Some tools will report this as 100% per core, others report it as 100% overall (so 12.5% for a single core, if you had 8 logical cores).– BobCommented Apr 18, 2014 at 14:13
-
1@Bob, true. I also wrote a multithreaded version, but it'll only work on Solaris: pastebin.com/enJfLR2L– mtakCommented Apr 18, 2014 at 14:16