Re: How to limit CPU utilization by ANY process with a perl script?
by tilly (Archbishop) on Feb 24, 2009 at 04:44 UTC
|
This shows how to do what you are asking for with cpulimits and a simple daemon written in shell. I would just use that, though porting it to Perl shouldn't be too hard if you really want to use Perl instead. | [reply] [Watch: Dir/Any] |
|
The listed program appears to issue SIGCONT and SIGSTOP to the offending program. This can work, but it just seems messy. Additionally, the application can ignore those signals, correct?
For a kludge, it seems like it would work. Having worked in academia, however, there are some percentage of users who will try to get around this. On the other hand, that is what the human side of policy is for (lock account, petition to have it reinstated, blah blah blah).
I still contend that this belongs in the scheduler. That being said, however, if this functionality does not exist in the scheduler, then the suggested solution is reasonable.
| [reply] [Watch: Dir/Any] |
Re: How to limit CPU utilization by ANY process with a perl script?
by bichonfrise74 (Vicar) on Feb 24, 2009 at 01:28 UTC
|
Not sure if this is what you want, but in Linux, you can do something like this...
ps aux | perl -lane 'print if $F[3] > 70'
This basically prints the CPU utilization if it is more than 70%. We can replace the 'print' with a force kill command if this is the answer to your question.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
However, in the case of an idle system, nice will not limit use to <= 70%. If the system is idle, it will still use as much as it needs to do what it is trying to do.
This is an issue for the OS scheduler, or each program needs to give up the processor voluntarily if it goes over 70%.
Update: or use something with SIGSTOP/SIGCONT - see tilly's post below.
| [reply] [Watch: Dir/Any] [d/l] |
|
Hmm, I think I might be misunderstanding what your one-liner is doing, but isn't the fourth element of @F %MEM, not %CPU?
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
marc 9764 0.0 1.9 85544 40380 ? S 15:47 0:07 pidgin
$ ps aux | perl -lane 'print if $F[3] == 1.9'
marc 9764 0.0 1.9 85500 40376 ? S 15:47 0:07 pidgin
And you didn't even know bears could type.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
That's true. In my case, the 4th element is for the CPU. I guess ps gives a different output depending on your Linux flavor.
| [reply] [Watch: Dir/Any] |
Re: How to limit CPU utilization by ANY process with a perl script?
by BrowserUk (Patriarch) on Feb 24, 2009 at 16:56 UTC
|
| [reply] [Watch: Dir/Any] [d/l] |
Re: How to limit CPU utilization by ANY process with a perl script?
by poolpi (Hermit) on Feb 24, 2009 at 13:27 UTC
|
You can probably realize something similar with
cpufreqd daemon under Unixes systems.
See
...command line tools to determine current CPUfreq settings and to modify them
I presume you want to participate to
distributed.net project ;)
hth, PooLpi
| [reply] [Watch: Dir/Any] |
Re: How to limit CPU utilization by ANY process with a perl script?
by roboticus (Chancellor) on Feb 24, 2009 at 18:28 UTC
|
unix.95054:
As MidLifeXis and BrowserUK imply, the requirement "ANY PROCESS AT ANY TIME SHOULD NOT USE MORE THAN 70% OF CPU" seems to be incorrectly specified. Rarely do you care what percentage of the CPU is spent on any particular process. Usually you care that the system is always responsive to the console, or that processes aren't CPU or I/O starved or some other criterion. Thus, the original statement appears to be symptom-related rather than requirement-related. You might ask them to restate the requirement in a more meaningful form. Otherwise, you'll have to do ridiculous things like consuming a third of the CPU in a high-priority process or otherwise discarding CPU cycles when they're otherwise unneeded by other processes.
...roboticus | [reply] [Watch: Dir/Any] |