Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
03-30-2006, 04:03 AM
|
#1
|
Member
Registered: Mar 2005
Distribution: FC5 on disk, Knoppix as LiveCD
Posts: 48
Rep:
|
resources: how to limit process to max. 20% CPU usage
1) Is it possible on linux kernel to start a process, that will use maximum of. e.g. 20% CPU?
2) Is it possible to change the CPU usage when the process is already running?
3) What about I/O usage? The network usage can be well limited, but what about disk usage or pipe usage?
The reason I would like to do this is simple... to lower CPU temperature and tweak troughput.
Example: a long program compile, prelink, any other cron job, folding@home, ...
I know about process and thread priorities, but what about limitind to a fixed number? Do I have to load some additional kernel module? My kernel is 2.6.16-1.2069_FC5.
|
|
|
03-30-2006, 06:37 AM
|
#2
|
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109
Rep:
|
Hi.
I don't think any of this is possible. It's not exactly high on most people's priority list to make their processes run _slower_.
You might have more luck changing the CPU clock speed. That can be done via a userspace utility, the name of which escapes me.
Incidentally, why not just run at full speed all the time? Do you have overheating problems?
Dave
|
|
|
03-30-2006, 06:51 AM
|
#3
|
Member
Registered: Mar 2005
Distribution: FC5 on disk, Knoppix as LiveCD
Posts: 48
Original Poster
Rep:
|
Overheating is one of problems too, since I like my computer to run healthy as well. I've installed silent cooling, but let the heat be different problem. E.g. on a notebook the problem persists, there's no way to make even idle job from turning on those loud ventilators.
I'd like to run one of my genetic algorithms, which it'd take about 14 days to finish. I don't like to run idle task, but if no other, I'll make it that way: "init.d + nice".
I've been thinking about this problem awhile now, but posted the question anyway, if anyone would tell me something interesting.
So the only way I could run a process under 20% CPU, it would be possible to check timers programmatically I guess...
The 2nd and 3rd questions from 1st post are left to some non-written kernel module I guess... Or am I wrong (wish I were...)?
|
|
|
03-30-2006, 09:50 AM
|
#4
|
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109
Rep:
|
Hi again.
You could run a watchdog script to pause and start the process. You could run it for one second out of five.
e.g.
Code:
#!/bin/bash
#Get the PID of the process
MYPID=`ps -u $USER | grep geneticAlg | awk '{ print $1 }'`
#Start and stop the process
while true; do kill -SIGSTOP $MYPID; sleep 4; kill -SIGCONT $MYPID; sleep 1; done
Should do the job.
Dave
|
|
|
03-30-2006, 02:49 PM
|
#5
|
Member
Registered: Mar 2005
Distribution: FC5 on disk, Knoppix as LiveCD
Posts: 48
Original Poster
Rep:
|
Dave,
very nice answer for CPU usage, thanks. I didn't come up with the idea I could do it with signals, but now it seems very reasonable.
I run your script now, and renice my chess engine for generic algorithm to 19.
Since the engine is asked every 5sec for an answer to new question, the 5+1 sec. interval would be too long, so I modified the intervals to 0.5+0.1sec, script is as follows:
Code:
#!/bin/bash
#Get the PID of the process
MYPID=`ps -u $USER | grep qchess | awk '{ print $1 }'`
#renice engine
renice +19 $MYPID
#renice watchdog
renice +5 $$
#Start and stop the process
while true; do kill -SIGSTOP $MYPID; sleep 0.5; kill -SIGCONT $MYPID; sleep 0.1; done
That's it.
I hope now I'll be able to compile Kdevelop 3.4 and everything will run smoothly, but that's another story.
Last edited by alesz; 03-30-2006 at 02:52 PM.
|
|
|
All times are GMT -5. The time now is 05:23 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|