1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 * Conky, a system monitor, based on torsmo
5 * Any original torsmo code is licensed under the BSD license
7 * All code written since the fork of torsmo is licensed under the GPL
9 * Please see COPYING for details
11 * Copyright (c) 2005 Adi Zaimi, Dan Piponi <dan@tanelorn.demon.co.uk>,
12 * Dave Clark <clarkd@skynet.ca>
13 * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
15 * All rights reserved.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 /* Ensure there's an operating system defined.
35 * compile with gcc -DOS ...
36 * There is *no* default because every OS has it's own way of revealing
37 * CPU/memory usage. */
39 /******************************************
41 ******************************************/
44 #include "text_object.h"
45 #define CPU_THRESHHOLD 0 /* threshhold for the cpu diff to appear */
60 #include <sys/types.h>
61 #include <sys/ioctl.h>
62 #include <sys/param.h>
67 /******************************************
69 ******************************************/
71 /* XXX: I shouldn't really use this BUFFER_LEN variable but scanf is so lame
72 * and it'll take me a while to write a replacement. */
73 #define BUFFER_LEN 1024
75 #define PROCFS_TEMPLATE "/proc/%d/stat"
76 #define PROCFS_TEMPLATE_MEM "/proc/%d/statm"
77 #define PROCFS_TEMPLATE_IO "/proc/%d/io"
78 #define PROCFS_CMDLINE_TEMPLATE "/proc/%d/cmdline"
79 #define MAX_SP 10 // number of elements to sort
96 /******************************************
98 ******************************************/
101 struct process *next;
102 struct process *previous;
107 // User and kernel times are in hundredths of seconds
108 unsigned long user_time;
110 unsigned long kernel_time;
111 unsigned long previous_user_time;
112 unsigned long previous_kernel_time;
113 unsigned long total_cpu_time;
117 unsigned long long read_bytes;
118 unsigned long long previous_read_bytes;
119 unsigned long long write_bytes;
120 unsigned long long previous_write_bytes;
123 unsigned int time_stamp;
124 unsigned int counted;
125 unsigned int changed;
128 struct sorted_process {
129 struct sorted_process *greater;
130 struct sorted_process *less;
131 struct process *proc;
134 /* Pointer to head of process list */
135 void process_find_top(struct process **, struct process **, struct process **
141 /* lookup a program by it's name */
142 struct process *get_process_by_name(const char *);
144 int parse_top_args(const char *s, const char *arg, struct text_object *obj);
145 void print_top(struct text_object *, char *, int);
146 void free_top(struct text_object *, int);
148 /* return zero on success, non-zero otherwise */
149 int set_top_name_width(const char *);