+======== Changes in 1.4 ============
+
+* We can now accept limits of 100% or higher. Useful for multi-core
+ systems.
+
+* Perform sanity check when getting jiffies. Should prevent memory
+ errors if we cannot open proc data.
+
+* Added copyright to README.
+
+
========== Changes in 1.3 ============
* Updated license information in cpulimit.c and README file
gcc -o cpulimit cpulimit.c -lrt $(CFLAGS)
install: cpulimit
+ mkdir -p ${PREFIX}/bin
+ mkdir -p ${PREFIX}/share/man/man1
cp cpulimit ${PREFIX}/bin
cp cpulimit.1.gz ${PREFIX}/share/man/man1
A copy of the license should be included with this program in a
file named LICENSE.
+Copyright 2005, Angelo Marletta <marlonx80@hotmail.com>
+Copyright 2011, Jesse Smith <jessefrgsmith@yahoo.ca>
+
Once you have downloaded a copy of LimitCPU building should be fairly
straight forward. First we unpack the source code
-tar zxf cpulimit-1.3.tar.gz
+tar zxf cpulimit-1.4.tar.gz
Then we run the makefile.
-cd cpulimit-1.3
+cd cpulimit-1.4
make
This should produce the executable file "cpulimit". If you would like
int getjiffies(int pid) {
static char stat[20];
static char buffer[1024];
+ char *p;
sprintf(stat,"/proc/%d/stat",pid);
FILE *f=fopen(stat,"r");
if (f==NULL) return -1;
- fgets(buffer,sizeof(buffer),f);
+ p = fgets(buffer,sizeof(buffer),f);
fclose(f);
- char *p=buffer;
- p=memchr(p+1,')',sizeof(buffer)-(p-buffer));
- int sp=12;
- while (sp--)
+ // char *p=buffer;
+ if (p)
+ {
+ p=memchr(p+1,')',sizeof(buffer)-(p-buffer));
+ int sp=12;
+ while (sp--)
p=memchr(p+1,' ',sizeof(buffer)-(p-buffer));
- //user mode jiffies
- int utime=atoi(p+1);
- p=memchr(p+1,' ',sizeof(buffer)-(p-buffer));
- //kernel mode jiffies
- int ktime=atoi(p+1);
- return utime+ktime;
+ //user mode jiffies
+ int utime=atoi(p+1);
+ p=memchr(p+1,' ',sizeof(buffer)-(p-buffer));
+ //kernel mode jiffies
+ int ktime=atoi(p+1);
+ return utime+ktime;
+ }
+ // could not read info
+ return -1;
}
//process instant photo
exit(1);
}
float limit=perclimit/100.0;
- if (limit<0 || limit >1) {
- fprintf(stderr,"Error: limit must be in the range 0-100\n");
+ if (limit <= 0.00) // || limit >1) {
+ {
+ fprintf(stderr,"Error: limit must be greater than 0\n");
print_usage (stderr, 1);
exit(1);
}
+cpulimit (1.4-1) UNRELEASED; urgency=low
+
+ * New upstream release
+
+ -- gregor herrmann <gregoa@debian.org> Sat, 13 Aug 2011 17:33:26 +0200
+
cpulimit (1.3-1) unstable; urgency=low
* New upstream release (LP: #200115).