I am monitoring CPU usage of python script which contains following code
from twisted.internet import reactor, task
def fun():
print "I don't know why CPU usage increases in the beginning"
lc = task.LoopingCall(fun)
lc.start(10)
reactor.run()
I am using ps command to get CPU usage(in percentage)
ps aux|grep <script_name>|grep -v grep|awk '{print $3}'
and condition is that it should not use CPU greater than 5%. But as soon as I executes the script, CPU usage goes to some 16% to 20%. After that, in 3 or 4 seconds it comes down to 1% or 2%. My question is, Why CPU usage increases to 16% to 20% in the beginning? I observed that when reactor starts running, CPU usage increases for some time. After that, it hardly uses CPU(0.3% to 0.4%) in my case.