I am trying to write a script for controling cpu usage of a VM n KVM using cpulimit. With cpulimit i can limit the cpu usage of a VM with pid say 2112 by :
./cpulimit -p 2112 -l 50.
I want to write a script which can open an interface
setcpu (vm_pid,limit)
Which can be called any number of times and I shud overwrite the existing limit. I can overwrite the existing limit by just adding the limit value as a runtime argument for the running cpulimit process. Like subprocess.Popen(..., stdin=subprocess.PIPE). I am a bit confused on how to grab the running process and provide runtime argument. For example (without scripting) :
# ./cpulimit -p 2112 -l 50
Process 2112 detected
Now It will set a cap on the process, Now I can simply enter
40
80
to overwrite the existing limit. I want to script this behavior . It will be great if you can provide a pointer or an idea on how to go about writing this script. Thanks a lot
- Sethu