Script (preferably Perl) to hog Linux CPU

Somebody in our local mailing list asked this and it also got my curious I decided to ask it as my first EE question:

How do I purposely hog CPU (in all cores) in a controlled manner? By controlled manner I mean hogging CPU by 70% only or 80%.  This means the script should actively monitor how much CPU it is burning and adjust its load generation accordingly.  Preferably done in Perl.

Any ideas/pointers?  Thanks
LVL 24
johanntagleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mwochnickCommented:
this module may get you started
http://search.cpan.org/~burak/Sys-Info-Base-0.73/lib/Sys/Info/Device/CPU.pm
look at the load function
mwochnickCommented:
johanntagleAuthor Commented:
Thanks mwochnick.  I guess I can have a main process that fires up a subprocess that generates x% load, check on the CPU load, then fires up more subprocesses as needed.  But how do you make a process run on a specific core, so that we can have all cores run at say 70% ?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mwochnickCommented:
you could create a process for each cpu and then pin each process to that cpu - here's an article on how to pin a process to a cpu - I think core's work the same as CPU's
http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
johanntagleAuthor Commented:
Thanks again mwochnick.  Turns out there's a non-Perl solution that does exactly what's needed - see http://www.devin.com/lookbusy/.  But I learned quite a few tricks from the links you gave.
johanntagleAuthor Commented:
Thanks again mwochnick.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.