Basically the Linux kernel already includes features to manage resources for any kind of process; and you can exploit that without writing C code.
To the contrary: you simply want to educate yourself how to use cgroups; and then you want to use the concepts behind that with "minimal" efforts on writing custom code on your side.
Do not re-invent the wheel here; as in: your wheel be (most likely) deficient compared to what the existing cgroups can do for you today!
But even when reading your comment, I don't get why you think you have to implement your own solution. If your program needs less than X%; you can't do anything about it anyway. And if it wants more than X; what is the point of creating your own proprietary mechanism of getting there?
Anyhow, maybe the cpulimit tool could help you getting there.
And, as your "real" problem seems to be: "how to generate CPU load"; well there are plenty of ways to get there, see here for example.