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.
30 #include <sys/types.h>
36 #define PIDHASH_SZ 1024
37 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
39 // a hierarchy of processes
40 struct process_family {
41 //the (god)father of the process family
43 //members list (father process is the first element)
46 //hashtable with all the processes (array of struct list of struct process)
47 struct list *hashtable[PIDHASH_SZ];
57 struct process_history *history;
60 // object to enumerate running processes
61 struct process_iterator {
66 // searches for all the processes derived from father and stores them
67 // in the process family struct
68 int create_process_family(struct process_family *f, int father);
70 // checks if there are new processes born in the specified family
71 // if any they are added to the members list
72 // the number of new born processes is returned
73 int check_new_members(struct process_family *f);
75 // removes a process from the family by its pid
76 void remove_process_from_family(struct process_family *f, int pid);
78 // free the heap memory used by a process family
79 void cleanup_process_family(struct process_family *f);
81 // searches a process given the name of the executable file, or its absolute path
82 // returns the pid, or 0 if it's not found
83 int look_for_process_by_name(const char *process);
85 // searches a process given its pid
86 // returns the pid, or 0 if it's not found
87 int look_for_process_by_pid(int pid);