If you want to control the specified process, this is usually done using scripts. Here is an example of perl. This puts the interest in the same way as the upper ones, and also resets them to one processor. Then, when a process is active, working with 2 threads, CPU utilization can be more than 100%. Take a special look at how processor cores are counted: D then let me show my example:
#!/usr/bin/perl my $pid=1234; #insert here monitored process PID #returns current process time counters or single undef if unavailable #returns: 1. process counter , 2. system counter , 3. total system cpu cores sub GetCurrentLoads { my $pid=shift; my $fh; my $line; open $fh,'<',"/proc/$pid/stat" or return undef; $line=<$fh>; close $fh; return undef unless $line=~/^\d+ \([^)]+\) \S \d+ \d+ \d+ \d+ -?\d+ \d+ \d+ \d+ \d+ \d+ (\d+) (\d+)/; my $TimeApp=$1+$2; my $TimeSystem=0; my $CpuCount=0; open $fh,'<',"/proc/stat" or return undef; while (defined($line=<$fh>)) { if ($line=~/^cpu\s/) { foreach my $nr ($line=~/\d+/g) { $TimeSystem+=$nr; }; next; }; $CpuCount++ if $line=~/^cpu\d/; } close $fh; return undef if $TimeSystem==0; return $TimeApp,$TimeSystem,$CpuCount; } my ($currApp,$currSys,$lastApp,$lastSys,$cores); while () { ($currApp,$currSys,$cores)=GetCurrentLoads($pid); printf "Load is: %5.1f\%\n",($currApp-$lastApp)/($currSys-$lastSys)*$cores*100 if defined $currApp and defined $lastApp and defined $currSys and defined $lastSys; ($lastApp,$lastSys)=($currApp,$currSys); sleep 1; }
I hope this helps you with any monitoring. Of course, you should use scanf or other C functions to convert any perl regexpes that I used for source C. Of course, 1 second for sleep is optional. You can use any time. effect, you get an average load for a certain period of time. When you will use it for monitoring, of course, you should set the last values outside. This is necessary because monitoring usually invokes scripts periodically, and the script should complete its work as soon as possible.
Znik May 27 '15 at 1:23 pm 2015-05-27 13:23
source share