From 880c2c9028816c16299771d6a482e4acea90b8f4 Mon Sep 17 00:00:00 2001 From: Paul Praet Date: Sun, 27 Oct 2013 13:39:51 +0100 Subject: [PATCH 1/5] Fix crash at CTRL_C --- src/cpulimit.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cpulimit.c b/src/cpulimit.c index 002205d..5c85da2 100644 --- a/src/cpulimit.c +++ b/src/cpulimit.c @@ -88,12 +88,14 @@ int lazy = 0; static void quit(int sig) { //let all the processes continue if stopped - struct list_node *node = NULL; - for (node=pgroup.proclist->first; node!= NULL; node=node->next) { - struct process *p = (struct process*)(node->data); - kill(p->pid, SIGCONT); - } - close_process_group(&pgroup); + if (pgroup.proclist != NULL){ + struct list_node *node = NULL; + for (node=pgroup.proclist->first; node!= NULL; node=node->next) { + struct process *p = (struct process*)(node->data); + kill(p->pid, SIGCONT); + } + close_process_group(&pgroup); + } //fix ^C little problem printf("\r"); fflush(stdout); From adc8140370cdb34c8fef1420be26fc076d3e7895 Mon Sep 17 00:00:00 2001 From: Angelo Marletta Date: Wed, 24 Dec 2014 03:41:42 +0100 Subject: [PATCH 2/5] remove assertion on parent pid --- src/process_group.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/process_group.c b/src/process_group.c index f1be459..06d73a6 100644 --- a/src/process_group.c +++ b/src/process_group.c @@ -172,7 +172,6 @@ void update_process_group(struct process_group *pgroup) else { assert(tmp_process.pid == p->pid); - assert(tmp_process.ppid == p->ppid); assert(tmp_process.starttime == p->starttime); add_elem(pgroup->proclist, p); if (dt < MIN_DT) continue; From 37f61593b40aa98b465692d9a40c6ac03264a29a Mon Sep 17 00:00:00 2001 From: Angelo Marletta Date: Sat, 27 Sep 2014 15:54:57 -0700 Subject: [PATCH 3/5] fix cppcheck warnings --- src/cpulimit.c | 4 +++- src/list.c | 7 +++---- src/memrchr.c | 5 ++--- src/process_iterator_linux.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cpulimit.c b/src/cpulimit.c index 9b25b87..dc61c3b 100644 --- a/src/cpulimit.c +++ b/src/cpulimit.c @@ -147,7 +147,7 @@ static void increase_priority() { /* Get the number of CPUs */ static int get_ncpu() { - int ncpu = -1; + int ncpu; #ifdef _SC_NPROCESSORS_ONLN ncpu = sysconf(_SC_NPROCESSORS_ONLN); #elif defined __APPLE__ @@ -156,6 +156,8 @@ static int get_ncpu() { sysctl(mib, 2, &ncpu, &len, NULL, 0); #elif defined _GNU_SOURCE ncpu = get_nprocs(); +#else + ncpu = -1; #endif return ncpu; } diff --git a/src/list.c b/src/list.c index a1c20a3..2a78358 100644 --- a/src/list.c +++ b/src/list.c @@ -66,7 +66,6 @@ void delete_node(struct list *l,struct list_node *node) { } l->count--; free(node); - node = NULL; } void destroy_node(struct list *l,struct list_node *node) { @@ -75,7 +74,7 @@ void destroy_node(struct list *l,struct list_node *node) { delete_node(l,node); } -int is_EMPTYLIST_list(struct list *l) { +int is_empty_list(struct list *l) { return (l->count==0?TRUE:FALSE); } @@ -123,8 +122,8 @@ void *locate_elem(struct list *l,void *elem) { } void clear_list(struct list *l) { - struct list_node *tmp; while(l->first!=EMPTYLIST) { + struct list_node *tmp; tmp=l->first; l->first=l->first->next; free(tmp); @@ -135,8 +134,8 @@ void clear_list(struct list *l) { } void destroy_list(struct list *l) { - struct list_node *tmp; while(l->first!=EMPTYLIST) { + struct list_node *tmp; tmp=l->first; l->first=l->first->next; free(tmp->data); diff --git a/src/memrchr.c b/src/memrchr.c index ba788f5..1f37870 100644 --- a/src/memrchr.c +++ b/src/memrchr.c @@ -26,10 +26,9 @@ memrchr(s, c, n) int c; size_t n; { - const unsigned char *cp; - if (n != 0) { - cp = (unsigned char *)s + n; + const unsigned char *cp; + cp = (unsigned char *)s + n; do { if (*(--cp) == (unsigned char)c) return((void *)cp); diff --git a/src/process_iterator_linux.c b/src/process_iterator_linux.c index 43c2771..c8cdd07 100644 --- a/src/process_iterator_linux.c +++ b/src/process_iterator_linux.c @@ -23,7 +23,7 @@ static int get_boot_time() { - int uptime; + int uptime = 0; FILE *fp = fopen ("/proc/uptime", "r"); if (fp != NULL) { @@ -103,7 +103,7 @@ static int read_process_info(pid_t pid, struct process *p) return -1; } fclose(fd); - sscanf(buffer, "%s", p->command); + strcpy(p->command, buffer); return 0; } From 8efde826648b108d804ef99b57e58c7e0b6df507 Mon Sep 17 00:00:00 2001 From: dt1973 Date: Thu, 12 Mar 2015 08:37:29 +0100 Subject: [PATCH 4/5] Fix build errors on FreeBSD --- src/cpulimit.c | 4 ++++ tests/process_iterator_test.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cpulimit.c b/src/cpulimit.c index dc61c3b..50eabea 100644 --- a/src/cpulimit.c +++ b/src/cpulimit.c @@ -43,6 +43,10 @@ #include #include +#ifdef __APPLE__ || __FREEBSD__ +#include +#endif + #include "process_group.h" #include "list.h" diff --git a/tests/process_iterator_test.c b/tests/process_iterator_test.c index 20ef479..1615196 100644 --- a/tests/process_iterator_test.c +++ b/tests/process_iterator_test.c @@ -28,7 +28,7 @@ #include #include -#ifdef __APPLE__ +#ifdef __APPLE__ || __FREEBSD__ #include #endif From 36394ead1f55c78526aa218bacad5e3cd7c5cc2c Mon Sep 17 00:00:00 2001 From: dt1973 Date: Thu, 12 Mar 2015 08:38:06 +0100 Subject: [PATCH 5/5] Convert README to Markdown --- README => README.md | 3 --- 1 file changed, 3 deletions(-) rename README => README.md (99%) diff --git a/README b/README.md similarity index 99% rename from README rename to README.md index af00bf9..019579d 100644 --- a/README +++ b/README.md @@ -1,9 +1,6 @@ CPULIMIT ======== -About ------ - Cpulimit is a tool which limits the CPU usage of a process (expressed in percentage, not in CPU time). It is useful to control batch jobs, when you don't want them to eat too many CPU cycles. The goal is prevent a process from running for more than a specified time ratio. It does not change the nice value or other scheduling priority settings, but 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 SIGSTOP and SIGCONT POSIX signals to processes. All the children processes and threads of the specified process will share the same percentage of CPU.