aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbhackerozzo <bhackerozzo@3b445381-d045-0410-9223-e17ecdb95f4b>2008-02-27 19:55:42 +0000
committerbhackerozzo <bhackerozzo@3b445381-d045-0410-9223-e17ecdb95f4b>2008-02-27 19:55:42 +0000
commit2993801ca6bc59ca78e3a55b24c1f64be1b4be1a (patch)
tree5203daa86246e65eb9116b6e6d28225bdce9deea
parentd0d6985abce54dd7bcf5b7702ff123330543ac15 (diff)
downloadcpulimit-2993801ca6bc59ca78e3a55b24c1f64be1b4be1a.tar.gz
setpriority() at startup
-rw-r--r--README34
-rw-r--r--cpulimit.c25
-rw-r--r--process.c2
-rw-r--r--procutils.c2
-rw-r--r--ptest.c2
5 files changed, 48 insertions, 17 deletions
diff --git a/README b/README
index d25fee5..6ffa82c 100644
--- a/README
+++ b/README
@@ -1,8 +1,20 @@
Cpulimit 1.2
+=======
+About:
+=======
+
+Cpulimit is a program that attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want they eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
+The control of the used cpu amount is done sending continue and stop POSIX signals to processes.
+All the children processes and threads of the specified process will share the same percent of cpu.
+
+Developed by Angelo Marletta.
+Please send your feedback, bug reports, feature requests to marlonx80 at hotmail dot com.
+
===========
Changelog:
===========
+
- reorganization of the code, splitted in more source files
- control function process_monitor() optimized by eliminating an unnecessary loop
- experimental support for multiple control of children processes and threads
@@ -15,6 +27,17 @@ Changelog:
- minor enhancements and bugfixes
+============================
+Get the latest source code:
+============================
+
+You can checkout the latest code from sourceforge Subversion repository, running:
+
+svn checkout https://cpulimit.svn.sourceforge.net/svnroot/cpulimit cpulimit
+
+Of course this is the development version, so you may experience bugs (please signal them!)
+
+
==============
Installation:
==============
@@ -22,14 +45,3 @@ Installation:
Run 'make' and place the executable file 'cpulimit' wherever you want.
Type 'cpulimit --help' to get documentation on available options.
-
-=======
-About:
-=======
-
-cpulimit is a program that attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want they eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
-The control of the used cpu amount is done sending continue and stop POSIX signals to processes.
-All the children processes and threads of the specified process will share the same percent of cpu.
-
-Developed by Angelo Marletta.
-Please send your feedback, bug reports, feature requests to marlonx80 at hotmail dot com.
diff --git a/cpulimit.c b/cpulimit.c
index c6cdb8b..6d950b4 100644
--- a/cpulimit.c
+++ b/cpulimit.c
@@ -36,7 +36,7 @@
* - cpu count detection, i.e. if you have 4 cpu, it is possible to limit up to 400%
* - in order to avoid deadlock, cpulimit prevents to limit itself
* - option --path eliminated, use --exe instead both for absolute path and file name
- * - deleted every setpriority(), (todo: set it just once)
+ * - deleted almost every setpriority(), just set it once at startup
* - minor enhancements and bugfixes
*
*/
@@ -69,6 +69,8 @@
//each slot is splitted in a working slice and a sleeping slice
#define CONTROL_SLOT 100000
+#define MAX_PRIORITY -10
+
//the "family"
struct process_family pf;
//pid of cpulimit
@@ -164,7 +166,7 @@ void limit_process(int pid, float limit)
create_process_family(&pf, pid);
struct list_node *node;
- printf("Members in the family owned by %d: %d\n", pf.father, pf.members.count);
+ if (verbose) printf("Members in the family owned by %d: %d\n", pf.father, pf.members.count);
while(1) {
@@ -206,7 +208,9 @@ void limit_process(int pid, float limit)
}
//average value
workingrate /= pf.members.count;
-
+
+ //TODO: make workingtime customized for each process, now it's equal for all
+
//adjust work and sleep time slices
if (pcpu>0) {
twork.tv_nsec = MIN(CONTROL_SLOT*limit*1000/pcpu*workingrate,CONTROL_SLOT*1000);
@@ -351,8 +355,19 @@ int main(int argc, char **argv) {
signal(SIGINT, quit);
signal(SIGTERM, quit);
- //TODO: try to renice
-
+ //try to renice with the best value
+ int old_priority = getpriority(PRIO_PROCESS, 0);
+ int priority = old_priority;
+ while (setpriority(PRIO_PROCESS, 0, priority-1) == 0 && priority>MAX_PRIORITY) {
+ priority--;
+ }
+ if (priority != old_priority) {
+ printf("Priority changed to %d\n", priority);
+ }
+ else {
+ printf("Cannot change priority\n");
+ }
+
while(1) {
//look for the target process..or wait for it
int ret = 0;
diff --git a/process.c b/process.c
index a16267b..e044fdc 100644
--- a/process.c
+++ b/process.c
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+//TODO: add documentation to public functions
+
#include "process.h"
int process_init(struct process_history *proc, int pid)
diff --git a/procutils.c b/procutils.c
index 0a64454..c203daf 100644
--- a/procutils.c
+++ b/procutils.c
@@ -59,7 +59,7 @@ static int get_starttime(int pid)
int sp = 20;
while (sp--)
p = memchr(p+1,' ',sizeof(buffer) - (p-buffer));
- //pid of the parent process
+ //start time of the process
int time = atoi(p+1);
return time;
}
diff --git a/ptest.c b/ptest.c
index 2901347..9fadb6f 100644
--- a/ptest.c
+++ b/ptest.c
@@ -5,6 +5,8 @@
#include <sys/wait.h>
#include "procutils.h"
+//simple program to test cpulimit
+
int main()
{
printf("PID %d\n", getpid());
Un proyecto texto-plano.xyz