|
|
Limit CPU usage for an application/process
As an old time Unix programmer, I know that this method can be dangerous! Even though signals are stacked for processes, it is possible that those processes that are not interactive that you try to control using SIGSTOP may lose track of signals. Signals are interrupts that are sent to a process when something outside of the program occurs that the process causes--such as trying to write to memory you do not have access to. SIGSTOP and SIGSTART is part of the jobs control that is usually entered from the terminal by pressing CTRL-Z.
Programs designed to handle this properly should be able to process SIGSTART in order to ensure the continuation of the program properly. Many non-interactive programs are not programmed to handle SIGSTART--it is assumed that these signals are used by interactive programs and not relevant for background processes.
Rather than using these signals, use the "nice" command to lower the priority of the process. Nominally, all processes start at priority 0. The priority can be set in the range of -20 (lowest) to +20 (highest). By lowering the scheduling priority you will let the underlying Mach operating system schedule other processes ahead of the one you want to limit access to CPU resources. It has the effect of lowering the scheduling priority to run the process during times when the operating system is idle, which is what you what to happen. It is a cleaner way to do what you want.
There are two ways to run processes at a lower priority. First, start the process using the "nice" command.
Make sure you add the ampersand to the end of the command so that the command is run in the background. Otherwise, if you want to change the scheduling priority of a running process, use the "renice" command. Find the process identification number (pid) of the running process and run the renice command:
Just as you lower the scheduling priority, you can also raise the scheduling priority. However, only the superuser can raise the scheduling priority. Thus, at the end of the day if you want to reset the priority of the process back to 0 (nominal), the use "sudo" to run the renice command. Using the process's pid, run:
Using "nice" and "renice" is more friendly to most running processes.
Nice does nothing to reduce thermal load
You are both right and wrong. I just had Handbrake crash on me using this script, which could be an example of the pitfalls of this method. Edited on Feb 02, '11 12:51:30PM by hamarkus
Nice does nothing to reduce thermal load
Just to let you know, I did compile and run cpulimit. You need to download it from http://cpulimit.sourceforge.net/ and make sure you have the latest version of the developer tools.
Nice does nothing to reduce thermal load
I tried cpulimit, checked it out and compiled it with make and ran it with: cpulimit$ ./cpulimit -l 80 -p 47879
Limit CPU usage for an application/process
Negative numbers in nice actually allow MORE cpu usage. Positive numbers cut priority down. ---
EMOJO: mojo no longer workin'
Limit CPU usage for an application/process
You're not quite right there... first off, it's SIGSTOP and SIGCONT, not SIGSTART, but I'll assume that's a typo. SIGSTOP isn't what is sent by the terminal when you press control-Z; that's SIGTSTP, which stands for "Tty SToP"; the signals are different because SIGSTOP cannot be trapped by the program you are controlling. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|