Limit CPU Usage in C++
<p>Is there a way to limit CPU usage in C++?</p>

<p>I mean can I write a program which takes input %CPU to be used and it uses maximum that much amount of CPU.</p>

<p>I basically want to add the functionality of cpulimit command internally in the program.</p>

<p>If there is, how to do it ?</p>

<p>Edits:</p>

<p>Environment: Linux (debian) with gcc 6.1. It should support as many arbitrary numbers as possible. i.e a range of 1% - 100% . If the OS cannot do, an error can be logged and the nearest value to it can be used or any other solution that is recommended when the OS restricts that number.</p>