Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all, I am trying to determine CPU usage on a radio controller running Linux. We have a script that another member of my work wrote using vmstat which I could not get any consistant results from. So, in an effort to understand what was going on I wrote a script using ps. Sadley after running several tests using both scripts, they do no match up at all, vmstat always gives me a much higher value. However, if I simply run the commands at any given time they do match up, therefore I believe that there is an error in one of the scripts. I am very new to linux and so I would very much appriciate a learned eye to look over these.
Here is the vmstat script:
#!/bin/bash
declare -i total
declare -i tries
tries=0
total=0
while [ $total -le 0 ]
do
if [ $tries -gt 6 ]; then
echo "You've tried entering a number $tries now. Maybe you should take a break and try again later."
exit
fi
if [ $tries -gt 3 ]; then
echo "Really? $tries attempts later and you're still not entering a number?"
fi
if [ $tries -gt 0 ]; then
if [ $tries -le 3 ]; then
echo "How about you enter a number this time?"
fi
fi
if [ $tries -le 0 ]; then
echo "How many seconds do you want the monitor to run for?"
fi
#!/bin/bash
# Test script to log each running process and it's CPU utilization.
#empty the log file
cat /dev/null > psstats.log
# Read in user input for test duration.
echo "How long would you like to run the test in seconds?"
read time
#Variables for timing
start="$(date +%s)"
elapsed=0
oldelapsed=0
lastreport=0
report=0
#Loop to run for a specific number of seconds given by the user above.
while [ $elapsed -lt $time ]
do
end="$(date +%s)"
oldelapsed=$elapsed
elapsed="$(expr $end - $start)"
report="$(expr $time - $elapsed)"
#If time has not elapsed or if an entire second has passed perform the test.
if [ $elapsed -eq 0 ] || [ $oldelapsed -eq $(expr $elapsed - 1) ] && [ $report -gt 0 ]; then
echo $(expr $elapsed + 1) >> psstats.log
ps -eo pcpu,pmem,vsz,pid,user,args >> psstats.log &
sleep 0.3
echo "===============================" >> psstats.log
echo $(expr $elapsed + 1) >> psstats.log
ps -eo pcpu,pmem,vsz,pid,user,args >> psstats.log &
sleep 0.3
echo "===============================" >> psstats.log
echo $(expr $elapsed + 1) >> psstats.log
ps -eo pcpu,pmem,vsz,pid,user,args >> psstats.log &
sleep 0.3
echo "===============================" >> psstats.log
fi
#Print out remaining time per second.
if [ $lastreport -ne $report ]; then
lastreport=$report
if [ $lastreport -ge 10 ]; then
echo "$lastreport seconds remaining..."
else
echo "0$lastreport seconds remaining..."
fi
fi
done
Distribution: Anything NOT SystemD (ie. M$) related.
Posts: 918
Rep:
Had any luck?
What have you tried so far?
The only suggestion that comes to mind is the two programs are just that.. two different programs, with possibly different nice settings, etc.. which if not completely aligned.. will give different answers.
I really don't undestand what you're trying to achieve.
If you want to know what the (entire) system has done over a period, probe /proc/stat at the beginning and end of the period. A small amount of basic maths will sort the numbers out.
Or try collectl - it maintains process data, but may be overkill for you.
Haven't had much time to work on this, our product went beta in the last few days so testing has been more urgent. Like I said i'm very green on Linux so i'm not sure what the nice settings are, i'm guessing command line options? As far as I have been able to test it seems like it's definatly a problem in the code of one of them. As I said earlier running the same command line functions with the same options as in the programs gives very consistant results. However the scripts run simultaniously gives very differing results... I don't know what to think other than i'm not giving the correct command line options to ps, however I have tested most of thos from the man file and haven't found any that give me more processes than I get with the -e option.
I really don't undestand what you're trying to achieve.
The system i'm testing is a Voice over IP radio controler, and by making radio calls using the system and monitoring the CPU usage i'm hoping to get a projection for maximum simultanious radio calls. Memory is not an issue, these calls take very little, however CPU gets eaten up the more calls that are currently on the system.
Therefore, my company had the above script using vmstat to take a sample very 1/3 of a second for however many seconds the user desires. However, upon running this the results were very erratic and inconsistant.
So, I am attempting to root cause this problem by writing my own script using ps to see what processess cause this erratice CPU usage.
Running multiple processes to scan /proc/ (after all that's what both vmstat and ps actully do) is always going to be dodgy. Despite your attempts to separate them by a third of a second, their dispatch after that is at the whim of the scheduler. They won't be at exactly 0.3 apart - and they'll be separate processes competing with everything else.
Go get collectl.
I'm gonna try this if I get time, it sounds like a much better program than either vmstat or ps. Thanks for the suggestion, i'll let you know how it works out.
Okay, so the big problem is that we are running Wind River which is not a very popular linux platform. I don't know, and doubt, that collectl would work on Wind River and we can't even compile it because we don't have a compiler that works with Wind River. Any suggestions/help with this?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.