3 * cpulimit - a cpu limiter for Linux
5 * Copyright (C) 2005-2008, by: Angelo Marletta <marlonx80@hotmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <sys/types.h>
35 //kernel time resolution (inverse of one jiffy interval) in Hertz
36 #define HZ sysconf(_SC_CLK_TCK)
37 //size of the history circular queue
38 #define HISTORY_SIZE 10
40 //extracted process statistics
46 //process instant photo
47 struct process_screenshot {
50 //total jiffies used by the process
52 //cpu time used since previous screenshot expressed in microseconds
57 struct process_history {
58 //the PID of the process
60 //name of /proc/PID/stat file
62 //read buffer for /proc filesystem
64 //recent history of the process (fixed circular queue)
65 struct process_screenshot history[HISTORY_SIZE];
66 //the index of the last screenshot made to the process
68 //the index of the oldest screenshot made to the process
70 //how many screenshots we have in the queue (max HISTORY_SIZE)
71 int actual_history_size;
72 //total cputime saved in the history
73 long total_workingtime;
75 struct cpu_usage usage;
78 int process_init(struct process_history *proc, int pid);
80 int process_monitor(struct process_history *proc, int last_working_quantum, struct cpu_usage *usage);
82 int process_close(struct process_history *proc);