Search code examples
linuxbashshellsleep

Simple way to "sleep" but consume CPU time


I am testing a scheduller that has a timeout based on a used CPU time.

To test it, I need some simple alternative that

will be equal to sleep <timeout is seconds as a float> that

will loop, i.e. utilize a CPU time and return once the timeout is elapsed.


How to write it simply in a shell?


Solution

  • One possible solution:

    timeout 5 sha1sum /dev/zero
    

    Advantages:

    • it uses timeout and sha1sum presented in any standard linux
    • sha1sum can be easily replaced with some multi-threaded command to utilize more than one CPU