2018-05-12 16:03:00 +00:00
|
|
|
/*
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2005-07-20 00:30:40 +00:00
|
|
|
*
|
2007-08-10 19:53:44 +00:00
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Adi Zaimi, Dan Piponi <dan@tanelorn.demon.co.uk>,
|
2008-02-20 20:30:45 +00:00
|
|
|
* Dave Clark <clarkd@skynet.ca>
|
2019-01-05 15:52:43 +00:00
|
|
|
* Copyright (c) 2005-2019 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 3 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
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-20 00:30:40 +00:00
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-06-14 05:32:46 +00:00
|
|
|
#ifndef _top_h_
|
|
|
|
#define _top_h_
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Ensure there's an operating system defined.
|
2005-07-20 00:30:40 +00:00
|
|
|
* compile with gcc -DOS ...
|
2008-02-20 20:30:45 +00:00
|
|
|
* There is *no* default because every OS has it's own way of revealing
|
|
|
|
* CPU/memory usage. */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/******************************************
|
|
|
|
* Includes *
|
|
|
|
******************************************/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#include "conky.h"
|
2009-08-05 22:46:51 +00:00
|
|
|
#include "text_object.h"
|
2020-12-31 08:09:23 +00:00
|
|
|
#define CPU_THRESHHOLD 0 /* threshold for the cpu diff to appear */
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <dirent.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <errno.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <math.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <signal.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
2009-06-13 22:02:50 +00:00
|
|
|
#include <sys/param.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <sys/stat.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <sys/time.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2011-10-10 19:54:18 +00:00
|
|
|
#include <pwd.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <regex.h>
|
2009-12-10 04:05:32 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/******************************************
|
|
|
|
* Defines *
|
|
|
|
******************************************/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* XXX: I shouldn't really use this BUFFER_LEN variable but scanf is so lame
|
|
|
|
* and it'll take me a while to write a replacement. */
|
2005-07-20 00:30:40 +00:00
|
|
|
#define BUFFER_LEN 1024
|
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
#define MAX_SP 10 // number of elements to sort
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/******************************************
|
|
|
|
* Process class *
|
|
|
|
******************************************/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-06-14 05:32:46 +00:00
|
|
|
struct process {
|
2018-05-12 16:03:00 +00:00
|
|
|
struct process *next;
|
|
|
|
struct process *previous;
|
|
|
|
|
|
|
|
pid_t pid;
|
|
|
|
char *name;
|
|
|
|
char *basename;
|
|
|
|
uid_t uid;
|
|
|
|
float amount;
|
|
|
|
// User and kernel times are in hundredths of seconds
|
|
|
|
unsigned long user_time;
|
|
|
|
unsigned long total;
|
|
|
|
unsigned long kernel_time;
|
|
|
|
unsigned long previous_user_time;
|
|
|
|
unsigned long previous_kernel_time;
|
|
|
|
unsigned long total_cpu_time;
|
|
|
|
unsigned long previous_total_cpu_time;
|
|
|
|
unsigned long long vsize;
|
|
|
|
unsigned long long rss;
|
2010-01-07 18:14:53 +00:00
|
|
|
#ifdef BUILD_IOSTATS
|
2018-05-12 16:03:00 +00:00
|
|
|
unsigned long long read_bytes;
|
|
|
|
unsigned long long previous_read_bytes;
|
|
|
|
unsigned long long write_bytes;
|
|
|
|
unsigned long long previous_write_bytes;
|
|
|
|
float io_perc;
|
2009-06-12 17:08:44 +00:00
|
|
|
#endif
|
2018-05-12 16:03:00 +00:00
|
|
|
unsigned int time_stamp;
|
|
|
|
unsigned int counted;
|
|
|
|
unsigned int changed;
|
2008-06-14 05:32:46 +00:00
|
|
|
};
|
|
|
|
|
2005-11-10 01:20:19 +00:00
|
|
|
struct sorted_process {
|
2018-05-12 16:03:00 +00:00
|
|
|
struct sorted_process *greater;
|
|
|
|
struct sorted_process *less;
|
|
|
|
struct process *proc;
|
2008-02-20 20:30:45 +00:00
|
|
|
};
|
2005-11-10 01:20:19 +00:00
|
|
|
|
2009-06-19 23:40:40 +00:00
|
|
|
/* lookup a program by it's name */
|
|
|
|
struct process *get_process_by_name(const char *);
|
|
|
|
|
2009-08-05 22:46:51 +00:00
|
|
|
int parse_top_args(const char *s, const char *arg, struct text_object *obj);
|
|
|
|
|
2010-05-30 11:55:50 +00:00
|
|
|
int update_top(void);
|
|
|
|
|
|
|
|
void get_top_info(void);
|
|
|
|
|
|
|
|
extern struct process *first_process;
|
|
|
|
extern unsigned long g_time;
|
|
|
|
|
2012-06-28 17:04:31 +00:00
|
|
|
struct process *get_process(pid_t pid);
|
2010-05-30 11:55:50 +00:00
|
|
|
|
2008-06-14 05:32:46 +00:00
|
|
|
#endif /* _top_h_ */
|