LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices

Reply
 
Search this Thread
Old 05-29-2005, 12:56 AM   #1
vanv101
LQ Newbie
 
Registered: Sep 2004
Posts: 9

Rep: Reputation: 0
Question process cpu usage


I was wondering how to set a specific cpu % usage for certain process. This is so I can limit Folding@Home usage specifically.

Thanks for any help.
 
Old 05-29-2005, 05:18 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
Re: process cpu usage

Quote:
Originally posted by vanv101
I was wondering how to set a specific cpu % usage for certain process. This is so I can limit Folding@Home usage specifically.

Thanks for any help.
You can use top to see the CPU usage of various programs.

Use /sbin/pidof 'Folding@home' (or top, or various other methods) to find the PID of the process/es. You can then use ps -o '%cpu' pid to find the average CPU usage of the process/es over its/their life.
 
Old 05-29-2005, 05:39 AM   #3
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Re: Re: process cpu usage

Quote:
Originally posted by rjlee
You can use top to see the CPU usage of various programs.

Use /sbin/pidof 'Folding@home' (or top, or various other methods) to find the PID of the process/es. You can then use ps -o '%cpu' pid to find the average CPU usage of the process/es over its/their life.
i think you misunderstood the question... vanv101's asking how to limit the cpu usage of certain processes - not how to see their current usage...
 
Old 05-29-2005, 07:18 AM   #4
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
Re: Re: Re: process cpu usage

Quote:
Originally posted by win32sux
i think you misunderstood the question... vanv101's asking how to limit the cpu usage of certain processes - not how to see their current usage...
Sorry!

As far as I am aware, there's still no absolute way to limit the CPU usage of a given process in Linux. You could start looking at soft real-time scheduling, which would give the process a fixed amount of your CPU time, but that's probably overkill.

Instead, Linux provides a less aggressive mechanism called the nice value. The schedular allocates a priority to each process by a number of factors how much the process volentarily sleeps, how much of the CPU it's been using in the past few milliseconds, and so on. One of the factors is called the niceness value.

The niceness value acts to increase or reduce the priority of a given process, after everything else has been calculated. Niceness ranges from -20 to +19; the default value is 0, higher values lower the priority and lower values increase it.

The amount of CPU time given to each process depends on its priority relative to other processes in the system (except that a process can deliberately sleep before its slice of the CPU is up, giving way to the next process).

So if you increase its niceness value, this decreases its priority and makes the process take less CPU time.

Code:
/sbin/renice +20 pids
You need to be the owner of a process (or root) to increase its niceness, and you need to be root to decrease it.
 
Old 05-29-2005, 06:41 PM   #5
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
i'm curious: what method could one use to set a niceness for a process that will be started in the future?? like, say that i want the firefox browser (for example) to have have a certain niceness whenever a user starts it...
 
Old 05-29-2005, 07:01 PM   #6
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
Quote:
Originally posted by win32sux
i'm curious: what method could one use to set a niceness for a process that will be started in the future?? like, say that i want the firefox browser (for example) to have have a certain niceness whenever a user starts it...
I've often wondered about that.

You can set the default niceness value for a new process (I think it inherits the value from the running /sbin/init process, but it might be settable somewhere else). I suppose that you could use an atd job or a daemon to renice processes by name, but that's hardly very clean (or secure).

You can always map the firefox command to use renice using alias, or by changing links under the desktop environment. You could even rename the binary and replace it with a shell command (or a simple C program) that calls the renamed binary through nice (possibly lying to it about its name).

My theory is that wanting to changing the niceness of a process tends to be an exceptional case, except for daemons which you can easily run through nice in the boot scripts in the first place.

Anyone else know how to do this?
 
Old 06-07-2005, 08:58 PM   #7
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
this program looks interesting: http://and.sourceforge.net/
 
Old 06-24-2005, 04:30 PM   #8
bhackerozzo
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Rep: Reputation: 0
hi, i just wrote a simple program that control max cpu usage of a process. it works well.

http://marlon80.interfree.it/cpulimit/index.html

angelo
 
Old 06-24-2005, 05:37 PM   #9
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
Quote:
Originally posted by bhackerozzo
hi, i just wrote a simple program that control max cpu usage of a process. it works well.

http://marlon80.interfree.it/cpulimit/index.html

angelo
Just taken a quick look at this. You might want to know that the maximum size of a path is defined as PATH_MAX in <limits.h>, and is 4096 on my system, which is more than the 1024 that you use.

This works by signalling a process to stop and continue, which will work well for background tasks where latancy isn't an issue. But I would be interested to see this working on an interactive process (and I suggest that it may make handling timing-sensitive devices like graphics tablets rather interesting).
 
Old 06-24-2005, 05:53 PM   #10
bhackerozzo
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Rep: Reputation: 0
Quote:
Just taken a quick look at this. You might want to know that the maximum size of a path is defined as PATH_MAX in <limits.h>, and is 4096 on my system, which is more than the 1024 that you use.

This works by signalling a process to stop and continue, which will work well for background tasks where latancy isn't an issue. But I would be interested to see this working on an interactive process (and I suggest that it may make handling timing-sensitive devices like graphics tablets rather interesting).
Thank you for bug reporting!
Now i have no idea how to grant both latency and cpu limit, perhaps this is impossible in user mode...because how can i know if a process that is actually stopped has received a signal such as an user input?
If you solve this issue, then this feature could be implemented in some way...obviously in user mode! (in kernel mode everything is possible...)
However i implemented this tool for seti@home and similar tasks. it is very good for controlling them.
Actually the only method to reduce latency is reduce period variable (declared in main).
Angelo

Last edited by bhackerozzo; 06-24-2005 at 05:57 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
How to get %CPU usage of a process devershetty Linux - Newbie 1 08-18-2008 01:52 AM
How to get %CPU usage of a process devershetty Linux - Newbie 13 08-16-2008 11:51 AM
Limiting a process CPU usage therandomthing Linux - Software 1 06-07-2005 09:00 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 02:17 PM


All times are GMT -5. The time now is 05:08 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration