{"id":665,"date":"2016-12-13T15:59:45","date_gmt":"2016-12-13T13:59:45","guid":{"rendered":"http:\/\/www.bashpi.org\/?page_id=665"},"modified":"2016-12-13T16:19:30","modified_gmt":"2016-12-13T14:19:30","slug":"top","status":"publish","type":"page","link":"https:\/\/www.bashpi.org\/?page_id=665","title":{"rendered":"top"},"content":{"rendered":"<p># use top to monitor process average cpu consumption in batch mode<br \/>\n# PID is set in beginning to avoid multiple changes<br \/>\n# Example below should perform 50 checks with delay 0.1 seconds and prints out average using awk.<\/p>\n<pre><code># PID=1234; top -b -d 0.1 -n 50 -p ${PID}|sed -e 's\/^[ \\t]*\/\/'| grep \"^${PID}\" |awk 'BEGIN{CPU=0;COUNT=0;}{CPU=CPU+$9;COUNT++}END{print int(CPU\/COUNT);}'\r\n7<\/code><\/pre>\n<p># same thing, without sed and grep<\/p>\n<pre><code># PID=2798; top -b -d 0.1 -n 50 -p ${PID} |awk -v PID=${PID} 'BEGIN{CPU=0;COUNT=0;}{if($1 == PID){CPU=CPU+$9;COUNT++};}END{print int(CPU\/COUNT);}'\r\n7<\/code><\/pre>\n<p>If you found this useful, say thanks, click on some banners or <a href=\"http:\/\/www.bashpi.org\/?page_id=105\">donate<\/a>, I can always use some beer money.<\/p>\n","protected":false},"excerpt":{"rendered":"<p># use top to monitor process average cpu consumption in batch mode # PID is set in beginning to avoid multiple changes # Example below should perform 50 checks with delay 0.1 seconds and prints out average using awk. # PID=1234; top -b -d 0.1 -n 50 -p ${PID}|sed -e &#8216;s\/^[ \\t]*\/\/&#8217;| grep &#8220;^${PID}&#8221; |awk [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":397,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-665","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=665"}],"version-history":[{"count":4,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/665\/revisions"}],"predecessor-version":[{"id":673,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/665\/revisions\/673"}],"up":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/397"}],"wp:attachment":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}