aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Marletta <angelo.marletta@gmail.com>2012-06-24 01:07:35 +0100
committerAngelo Marletta <angelo.marletta@gmail.com>2012-06-24 01:07:35 +0100
commitd7373dde5dde22945524d09e2c3f7f1a8290c6b9 (patch)
tree3bdcf882276326dd307b44416e10024429c48235
parent157117a985b0ba13b8df6ac164c57027e4374216 (diff)
parent67952f5cca213420e7fb5ea68c03061a63824655 (diff)
downloadcpulimit-d7373dde5dde22945524d09e2c3f7f1a8290c6b9.tar.gz
Merge branch 'develop'
-rw-r--r--LICENSE2
-rw-r--r--README10
-rw-r--r--src/cpulimit.c24
-rw-r--r--src/list.c43
-rw-r--r--src/list.h9
-rw-r--r--src/process_group.c21
-rw-r--r--src/process_group.h4
-rw-r--r--src/process_iterator.c21
-rw-r--r--src/process_iterator.h4
-rw-r--r--src/process_iterator_apple.c21
-rw-r--r--src/process_iterator_freebsd.c21
-rw-r--r--src/process_iterator_linux.c21
-rw-r--r--src/procutils.h94
-rw-r--r--tests/process_iterator_test.c21
14 files changed, 161 insertions, 155 deletions
diff --git a/LICENSE b/LICENSE
index 06ba570..97f263e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
cpulimit - a CPU usage limiter for Linux
-Copyright (C) 2012 Angelo Marletta
+Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
diff --git a/README b/README
index 6760147..15f0691 100644
--- a/README
+++ b/README
@@ -4,17 +4,18 @@ CPULIMIT
About
=======
-Cpulimit is a tool which attempts to limit 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 on the real CPU usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
+Cpulimit is a tool which attempts to limit 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 percent of CPU.
Developed by Angelo Marletta.
Please send your feedback, bug reports, feature requests or just thanks.
-=====================
- Changelog since 1.1
-=====================
+===========
+ Changelog
+===========
+- added support for FreeBSD
- reorganization of the code, splitted in more source files
- cpu count detection, i.e. if you have 4 cpu, it is possible to limit up to 400%
- in order to avoid deadlocks, cpulimit now prevents to limit itself
@@ -25,7 +26,6 @@ Please send your feedback, bug reports, feature requests or just thanks.
- cpulimit exits if --lazy option is specified and the process terminates
- target process can be created on-fly given command line
- light and scalable algorithm for subprocesses detection and limitation
-- mac os support
- minor enhancements and bugfixes
============================
diff --git a/src/cpulimit.c b/src/cpulimit.c
index 394b132..5353b90 100644
--- a/src/cpulimit.c
+++ b/src/cpulimit.c
@@ -1,8 +1,8 @@
/**
*
- * cpulimit - a cpu limiter for Linux
+ * cpulimit - a CPU limiter for Linux
*
- * Copyright (C) 2005-2008, by: Angelo Marletta <marlonx80@hotmail.com>
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -18,28 +18,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- **********************************************************************
+ **************************************************************
*
* This is a simple program to limit the cpu usage of a process
* If you modify this code, send me a copy please
*
- * Date: 30/8/2008
- * Version: 1.2 beta
- * Get the latest version at: http://cpulimit.sourceforge.net
- *
- * Changelog from 1.1:
- * - reorganization of the code, splitted in more source files
- * - cpu count detection, i.e. if you have 4 cpu, it is possible to limit up to 400%
- * - in order to avoid deadlocks, cpulimit now prevents to limit itself
- * - option --path eliminated, use --exe instead both for absolute path and file name
- * - call setpriority() just once in limit_process()
- * - no more segmentation fault when processes exit
- * - no more memory corruption when processes exit
- * - cpulimit exits if --lazy option is specified and the process terminates
- * - target process can be created on-fly given command line
- * - light and scalable algorithm for subprocesses detection and limitation
- * - mac os support
- * - minor enhancements and bugfixes
+ * Get the latest version at: http://github.com/opsengine/cpulimit
*
*/
diff --git a/src/list.c b/src/list.c
index 6fe1e06..a1c20a3 100644
--- a/src/list.c
+++ b/src/list.c
@@ -1,28 +1,23 @@
/**
-*
-* cpulimit - a cpu limiter for Linux
-*
-* Copyright (C) 2005-2008, by: Angelo Marletta <marlonx80@hotmail.com>
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-**********************************************************************
-*
-* Dynamic list implementation
-*
-*/
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
#include <stdlib.h>
#include <string.h>
diff --git a/src/list.h b/src/list.h
index 478635f..0b43a2b 100644
--- a/src/list.h
+++ b/src/list.h
@@ -1,8 +1,8 @@
/**
*
- * cpulimit - a cpu limiter for Linux
+ * cpulimit - a CPU limiter for Linux
*
- * Copyright (C) 2005-2008, by: Angelo Marletta <marlonx80@hotmail.com>
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -17,11 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- **********************************************************************
- *
- * Dynamic list interface
- *
*/
#ifndef __LIST__
diff --git a/src/process_group.c b/src/process_group.c
index 71f180b..671dd73 100644
--- a/src/process_group.c
+++ b/src/process_group.c
@@ -1,3 +1,24 @@
+/**
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#include <string.h>
#include <stdlib.h>
#include <limits.h>
diff --git a/src/process_group.h b/src/process_group.h
index 100711d..ab86816 100644
--- a/src/process_group.h
+++ b/src/process_group.h
@@ -1,8 +1,8 @@
/**
*
- * cpulimit - a cpu limiter for Linux
+ * cpulimit - a CPU limiter for Linux
*
- * Copyright (C) 2005-2012, by: Angelo Marletta <marlonx80@hotmail.com>
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/process_iterator.c b/src/process_iterator.c
index 0e31c81..165f420 100644
--- a/src/process_iterator.c
+++ b/src/process_iterator.c
@@ -1,3 +1,24 @@
+/**
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/process_iterator.h b/src/process_iterator.h
index 82fadac..ecbe995 100644
--- a/src/process_iterator.h
+++ b/src/process_iterator.h
@@ -1,8 +1,8 @@
/**
*
- * cpulimit - a cpu limiter for Linux
+ * cpulimit - a CPU limiter for Linux
*
- * Copyright (C) 2005-2012, by: Angelo Marletta <marlonx80@hotmail.com>
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/process_iterator_apple.c b/src/process_iterator_apple.c
index ee574e7..d7aa5f3 100644
--- a/src/process_iterator_apple.c
+++ b/src/process_iterator_apple.c
@@ -1,3 +1,24 @@
+/**
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
int init_process_iterator(struct process_iterator *it) {
return 0;
}
diff --git a/src/process_iterator_freebsd.c b/src/process_iterator_freebsd.c
index eb6cfaa..a4bf38f 100644
--- a/src/process_iterator_freebsd.c
+++ b/src/process_iterator_freebsd.c
@@ -1,3 +1,24 @@
+/**
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#include <sys/sysctl.h>
#include <sys/user.h>
#include <fcntl.h>
diff --git a/src/process_iterator_linux.c b/src/process_iterator_linux.c
index a15be45..9e2f7f2 100644
--- a/src/process_iterator_linux.c
+++ b/src/process_iterator_linux.c
@@ -1,3 +1,24 @@
+/**
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#include <sys/vfs.h>
static int get_boot_time()
diff --git a/src/procutils.h b/src/procutils.h
deleted file mode 100644
index c39a239..0000000
--- a/src/procutils.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- *
- * cpulimit - a cpu limiter for Linux
- *
- * Copyright (C) 2005-2008, by: Angelo Marletta <marlonx80@hotmail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef __PROCUTILS_H
-
-#define __PROCUTILS_H
-
-#include <sys/types.h>
-#include <dirent.h>
-
-#include "list.h"
-#include "process.h"
-
-#define PIDHASH_SZ 1024
-#define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
-
-// a hierarchy of processes
-struct process_family {
- //the (god)father of the process family
- pid_t father;
- //process list (father process is the first element)
- //elements are struct process
- struct list members;
- //non-members list
- //hashtable with all the processes (array of struct list of struct process)
- struct list *proctable[PIDHASH_SZ];
- //total process count
- int count;
-};
-
-//TODO: use this object in proctable and delete member in struct process
-struct table_item {
- struct process *proc;
- //1 if the process is a member of the family
- int member;
-};
-
-// object to enumerate running processes
-struct process_iterator {
-#ifdef __linux__
- DIR *dip;
- struct dirent *dit;
-#elif defined __APPLE__
- struct kinfo_proc *procList;
- int count;
- int c;
-#elif defined __FreeBSD__
- int count;
-#endif
- struct process *current;
-};
-
-// searches for all the processes derived from father and stores them
-// in the process family struct
-int create_process_family(struct process_family *f, pid_t father);
-
-// checks if there are new processes born in the specified family
-// if any they are added to the members list
-// the number of new born processes is returned
-int update_process_family(struct process_family *f);
-
-// removes a process from the family by its pid
-void remove_process_from_family(struct process_family *f, pid_t pid);
-
-// free the heap memory used by a process family
-void cleanup_process_family(struct process_family *f);
-
-// searches a process given the name of the executable file, or its absolute path
-// returns the pid, or 0 if it's not found
-int look_for_process_by_name(const char *process_name);
-
-// searches a process given its pid
-// returns the pid, or 0 if it's not found
-int look_for_process_by_pid(pid_t pid);
-
-#endif
diff --git a/tests/process_iterator_test.c b/tests/process_iterator_test.c
index f5b7586..7b1c6b5 100644
--- a/tests/process_iterator_test.c
+++ b/tests/process_iterator_test.c
@@ -1,3 +1,24 @@
+/**
+ *
+ * cpulimit - a CPU limiter for Linux
+ *
+ * Copyright (C) 2005-2012, by: Angelo Marletta <angelo dot marletta at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
Un proyecto texto-plano.xyz