1

OS: CentOS 7.9

I want to simulate/create 1 process for test purposes, such that top reports it consuming more than %100 CPU. Something looks like below in ps output;

   USER         PID    %CPU     COMMAND
user.one        111245  1500    command

There are stress and stress-ng commands but they only allow 100

-l P, --cpu-load P         load CPU by P %%, 0=sleep, 100=full load (see -c)

I also tried to run the stress command with mpirun with oversubscribed option but no luck.

    -oversubscribe, --oversubscribe
Nodes are allowed to be oversubscribed, even on a managed system, and overloading of processing elements. 

Thank you in advance!

5
  • 2
    If I had known I could run my CPU at 200%, I am 110% certain that I would not have paid for a second CPU. Commented Apr 28, 2022 at 16:56
  • This is just the way Linux interprets some parallel processes. You should probably see some threads people complaining about +%100 CPU usage in their top command. I wouldn't expect this kind of a replay from a guy with a 6,457 reputations. Commented Apr 28, 2022 at 20:54
  • I was flippant but not inaccurate. top is inconsistent in the way it aggregates CPU usage in different places, and in how threads are treated as processes. It averages stats over several seconds, which introduces anomalies. It does not even differentiate CPUs from cores. stress lives in the real world -- it blitzes one core until it consumes every available cycle. Commented Apr 29, 2022 at 7:38
  • Thank you for the information, right, you can also disable this behavior and exit irix mode at the top by pressing "SHIFT + i " Long story short, there are some processes in my production system with this behavior, I want to simulate this behavior. I believe there should be a simple loop code to provide this but I couldn't find it on the net. Commented Apr 29, 2022 at 9:11
  • I've adjusted the wording to try to clear it up. Asking for more than 100% of anything tangible ("of the CPU") is nonsense. Commented Apr 29, 2022 at 9:56

1 Answer 1

2

If you don't want to compile your own testing application which will use for example pthread_create(3) to create multiple threads, which will get each 100% CPU usage added to the process once they are looping forever doing nothing, you can use an on-the-shelf tool that requires heavy computation and is thus implemented to do parallel processing.

Here's a sample of such tools, all doing parallel compression: pigz, pixz, pbzip2.

For CentOS 7, once EPEL repository is made available (by installing the epel-release package), an other/older implementation for parallel XZ is available in the package and command pxz (which has a slightly different syntax than pixz).

pxz </dev/zero >/dev/null

should reach almost n x 100% CPU usage for the single (multi-threaded) process if nothing else consumes resources. By default n = the result of the command nproc.

You can limit to less than n x 100% with its -T n option.

1
  • Great, Thank you. pxz did the job, and sorry If I was not clear at first. Commented Apr 29, 2022 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .