cf0fccf3f8e18bc40fb76e9f486155c0fbffc219
[monky] / src / top.h
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Any original torsmo code is licensed under the BSD license
4  *
5  * All code written since the fork of torsmo is licensed under the GPL
6  *
7  * Please see COPYING for details
8  *
9  * Copyright (c) 2005 Adi Zaimi, Dan Piponi <dan@tanelorn.demon.co.uk>,
10  *                                        Dave Clark <clarkd@skynet.ca>
11  * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
12  *      (see AUTHORS)
13  * All rights reserved.
14  *
15  * This program is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  *
27  * $Id$ */
28
29 /* Ensure there's an operating system defined.
30  * compile with gcc -DOS ...
31  * There is *no* default because every OS has it's own way of revealing
32  * CPU/memory usage. */
33
34 /******************************************
35  * Includes                                                               *
36  ******************************************/
37
38 #include "conky.h"
39 #define CPU_THRESHHOLD  0       /* threshhold for the cpu diff to appear */
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <time.h>
43 #include <dirent.h>
44 #include <string.h>
45 #include <fcntl.h>
46 #include <unistd.h>
47 #include <ctype.h>
48 #include <math.h>
49 #include <assert.h>
50 #include <limits.h>
51 #include <errno.h>
52 #include <signal.h>
53
54 #include <sys/wait.h>
55 #include <sys/stat.h>
56 #include <sys/param.h>
57 #include <sys/types.h>
58 #include <sys/ioctl.h>
59 #include <sys/time.h>
60
61 #include <regex.h>
62
63 /******************************************
64  * Defines                                                                *
65  ******************************************/
66
67 /* XXX: I shouldn't really use this BUFFER_LEN variable but scanf is so lame
68  * and it'll take me a while to write a replacement. */
69 #define BUFFER_LEN 1024
70
71 #define PROCFS_TEMPLATE "/proc/%d/stat"
72 #define PROCFS_TEMPLATE_MEM "/proc/%d/statm"
73 #define PROCFS_CMDLINE_TEMPLATE "/proc/%d/cmdline"
74 #define MAX_SP 10       // number of elements to sort
75
76 /******************************************
77  * Process class                                                  *
78  ******************************************/
79
80 struct sorted_process {
81         struct sorted_process *greater;
82         struct sorted_process *less;
83         struct process *proc;
84 };
85
86 /* Pointer to head of process list */
87 void process_find_top(struct process **, struct process **);