Process.h 4.68 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
/* Do not edit this file. It was automatically generated. */
Hisham Muhammad's avatar
Hisham Muhammad committed
2
3
4
5
6

#ifndef HEADER_Process
#define HEADER_Process
/*
htop - Process.h
Hisham Muhammad's avatar
Hisham Muhammad committed
7
(C) 2004-2015 Hisham H. Muhammad
Hisham Muhammad's avatar
Hisham Muhammad committed
8
9
10
11
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

sherpya's avatar
sherpya committed
12
13
14
15
16
#ifdef __ANDROID__
#define SYS_ioprio_get __NR_ioprio_get
#define SYS_ioprio_set __NR_ioprio_set
#endif

17
// On Linux, this works only with glibc 2.1+. On earlier versions
Hisham Muhammad's avatar
Hisham Muhammad committed
18
// the behavior is similar to have a hardcoded page size.
19
#ifndef PAGE_SIZE
Hisham Muhammad's avatar
Hisham Muhammad committed
20
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) )
21
#endif
Hisham Muhammad's avatar
Hisham Muhammad committed
22
#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K )
Hisham Muhammad's avatar
Hisham Muhammad committed
23

Hisham Muhammad's avatar
Hisham Muhammad committed
24
#include "Object.h"
25

Hisham Muhammad's avatar
Hisham Muhammad committed
26
#include <sys/types.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
27
#include <inttypes.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
28

29
#define PROCESS_FLAG_IO 0x0001
30

31
typedef enum ProcessFields {
Hisham's avatar
Hisham committed
32
   NULL_PROCESSFIELD = 0,
33
34
35
36
37
38
39
40
41
42
43
44
45
   PID = 1,
   COMM = 2,
   STATE = 3,
   PPID = 4,
   PGRP = 5,
   SESSION = 6,
   TTY_NR = 7,
   TPGID = 8,
   MINFLT = 10,
   MAJFLT = 12,
   PRIORITY = 18,
   NICE = 19,
   STARTTIME = 21,
46
   PROCESSOR = 38,
47
48
49
50
51
52
53
54
55
56
   M_SIZE = 39,
   M_RESIDENT = 40,
   ST_UID = 46,
   PERCENT_CPU = 47,
   PERCENT_MEM = 48,
   USER = 49,
   TIME = 50,
   NLWP = 51,
   TGID = 52,
} ProcessField;
Hisham Muhammad's avatar
Hisham Muhammad committed
57

58
59
60
61
62
typedef struct ProcessPidColumn_ {
   int id;
   char* label;
} ProcessPidColumn;

Hisham Muhammad's avatar
Hisham Muhammad committed
63
64
65
typedef struct Process_ {
   Object super;

Hisham Muhammad's avatar
Hisham Muhammad committed
66
   struct Settings_* settings;
Hisham Muhammad's avatar
Hisham Muhammad committed
67

68
   unsigned long long int time;
Hisham Muhammad's avatar
Hisham Muhammad committed
69
   pid_t pid;
70
71
   pid_t ppid;
   pid_t tgid;
Hisham Muhammad's avatar
Hisham Muhammad committed
72
   char* comm;
73
   int commLen;
Hisham Muhammad's avatar
Hisham Muhammad committed
74
   int indent;
75
76
77
78

   int basenameOffset;
   bool updated;

Hisham Muhammad's avatar
Hisham Muhammad committed
79
80
   char state;
   bool tag;
Hisham Muhammad's avatar
Hisham Muhammad committed
81
   bool showChildren;
82
   bool show;
83
84
85
   unsigned int pgrp;
   unsigned int session;
   unsigned int tty_nr;
86
   int tpgid;
87
   uid_t st_uid;
Hisham Muhammad's avatar
Hisham Muhammad committed
88
   unsigned long int flags;
89
   int processor;
Hisham Muhammad's avatar
Hisham Muhammad committed
90
91
92
93
94

   float percent_cpu;
   float percent_mem;
   char* user;

Hisham Muhammad's avatar
Hisham Muhammad committed
95
96
   long int priority;
   long int nice;
97
   long int nlwp;
Hisham Muhammad's avatar
Hisham Muhammad committed
98
99
   char starttime_show[8];
   time_t starttime_ctime;
Hisham Muhammad's avatar
Hisham Muhammad committed
100

101
102
   long m_size;
   long m_resident;
Hisham Muhammad's avatar
Hisham Muhammad committed
103
104
105
106
107

   int exit_signal;

   unsigned long int minflt;
   unsigned long int majflt;
108
   #ifdef DEBUG
Hisham Muhammad's avatar
Hisham Muhammad committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
   long int itrealvalue;
   unsigned long int vsize;
   long int rss;
   unsigned long int rlim;
   unsigned long int startcode;
   unsigned long int endcode;
   unsigned long int startstack;
   unsigned long int kstkesp;
   unsigned long int kstkeip;
   unsigned long int signal;
   unsigned long int blocked;
   unsigned long int sigignore;
   unsigned long int sigcatch;
   unsigned long int wchan;
   unsigned long int nswap;
   unsigned long int cnswap;
   #endif

Hisham Muhammad's avatar
Hisham Muhammad committed
127
128
} Process;

Hisham Muhammad's avatar
Hisham Muhammad committed
129
130
131
132
typedef struct ProcessFieldData_ {
   const char* name;
   const char* title;
   const char* description;
133
   uint64_t flags;
Hisham Muhammad's avatar
Hisham Muhammad committed
134
} ProcessFieldData;
Hisham Muhammad's avatar
Hisham Muhammad committed
135

136
// Implemented in platform-specific code:
Hisham Muhammad's avatar
Hisham Muhammad committed
137
138
void Process_writeField(Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
139
140
141
void Process_delete(Object* cast);
bool Process_isThread(Process* this);
extern ProcessFieldData Process_fields[];
142
143
extern ProcessPidColumn Process_pidColumns[];
extern char Process_pidFormat[20];
Hisham Muhammad's avatar
Hisham Muhammad committed
144

145
typedef Process*(*Process_New)(struct Settings_*);
146
147
148
149
150
151
152
153
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);

typedef struct ProcessClass_ {
   const ObjectClass super;
   const Process_WriteField writeField;
} ProcessClass;

#define As_Process(this_)              ((ProcessClass*)((this_)->super.klass))
154

155
156
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))

157
158
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))

159

160
#define ONE_K 1024L
161
162
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
Hisham Muhammad's avatar
Hisham Muhammad committed
163

164
#define ONE_DECIMAL_K 1000L
Hisham Muhammad's avatar
Hisham Muhammad committed
165
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
166
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
Hisham Muhammad's avatar
Hisham Muhammad committed
167

168
169
extern char Process_pidFormat[20];

170
171
void Process_setupColumnWidths();

172
173
174
175
void Process_humanNumber(RichString* str, unsigned long number, bool coloring);

void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);

176
void Process_printTime(RichString* str, unsigned long long totalHundredths);
177
178
179

void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);

180
181
void Process_printPercentage(float val, char* buffer, int n, int* attr);

182
183
184
void Process_writeField(Process* this, RichString* str, ProcessField field);

void Process_display(Object* cast, RichString* out);
Hisham Muhammad's avatar
Hisham Muhammad committed
185

186
void Process_done(Process* this);
Hisham Muhammad's avatar
Hisham Muhammad committed
187

188
extern ProcessClass Process_class;
189

190
void Process_init(Process* this, struct Settings_* settings);
191

Hisham Muhammad's avatar
Hisham Muhammad committed
192
193
void Process_toggleTag(Process* this);

194
bool Process_setPriority(Process* this, int priority);
Hisham Muhammad's avatar
Hisham Muhammad committed
195

196
197
198
bool Process_changePriorityBy(Process* this, size_t delta);

void Process_sendSignal(Process* this, size_t sgn);
Hisham Muhammad's avatar
Hisham Muhammad committed
199

200
long Process_pidCompare(const void* v1, const void* v2);
201

202
long Process_compare(const void* v1, const void* v2);
Hisham Muhammad's avatar
Hisham Muhammad committed
203
204

#endif