LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 03-30-2006, 04:03 AM   #1
alesz
Member
 
Registered: Mar 2005
Distribution: FC5 on disk, Knoppix as LiveCD
Posts: 48

Rep: Reputation: 15
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.
 
Old 03-30-2006, 06:37 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
 
Old 03-30-2006, 06:51 AM   #3
alesz
Member
 
Registered: Mar 2005
Distribution: FC5 on disk, Knoppix as LiveCD
Posts: 48

Original Poster
Rep: Reputation: 15
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...)?
 
Old 03-30-2006, 09:50 AM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
 
Old 03-30-2006, 02:49 PM   #5
alesz
Member
 
Registered: Mar 2005
Distribution: FC5 on disk, Knoppix as LiveCD
Posts: 48

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
limit cpu % usage for a process student04 Linux - General 15 03-18-2014 07:22 PM
Limit CPU usage slantoflight Linux - General 5 02-23-2006 03:37 AM
max % of CPU for one process uselpa Slackware 2 07-30-2005 08:21 AM
limit cpu usage by mysql eduac Linux - Software 3 06-08-2004 05:08 PM
max process limit anoop_chandran Linux - Networking 2 01-16-2002 05:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration