Process.h 4.95 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-2011 Hisham H. Muhammad
Hisham Muhammad's avatar
Hisham Muhammad committed
8
9
10
11
12
13
14
15
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "ProcessList.h"
#include "Object.h"
#include "CRT.h"
#include "String.h"
16
#include "RichString.h"
17
#include "Affinity.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include "debug.h"

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdbool.h>
#include <pwd.h>
32
#include <sched.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
33
#include <time.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
34

35
36
#ifdef HAVE_HWLOC
#include <hwloc/linux.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
37
#endif
38

Hisham Muhammad's avatar
Hisham Muhammad committed
39
40
// This works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size.
41
#ifndef PAGE_SIZE
Hisham Muhammad's avatar
Hisham Muhammad committed
42
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) )
43
#endif
Hisham Muhammad's avatar
Hisham Muhammad committed
44
#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K )
Hisham Muhammad's avatar
Hisham Muhammad committed
45
46


47
48
49
50
51
52
53
#ifndef Process_isKernelThread
#define Process_isKernelThread(_process) (_process->pgrp == 0)
#endif

#ifndef Process_isUserlandThread
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
#endif
Hisham Muhammad's avatar
Hisham Muhammad committed
54

Hisham Muhammad's avatar
Hisham Muhammad committed
55
#ifndef Process_isThread
56
#define Process_isThread(_process) (Process_isUserlandThread(_process) || Process_isKernelThread(_process))
Hisham Muhammad's avatar
Hisham Muhammad committed
57
58
#endif

Hisham Muhammad's avatar
Hisham Muhammad committed
59
60
61
62
63
typedef enum ProcessField_ {
   PID = 1, COMM, STATE, PPID, PGRP, SESSION, TTY_NR, TPGID, FLAGS, MINFLT, CMINFLT, MAJFLT, CMAJFLT, UTIME,
   STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
   STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
   PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
64
   USER, TIME, NLWP, TGID,
65
   #ifdef HAVE_OPENVZ
66
   CTID, VPID,
67
   #endif
Hisham Muhammad's avatar
Hisham Muhammad committed
68
69
70
   #ifdef HAVE_VSERVER
   VXID,
   #endif
71
   #ifdef HAVE_TASKSTATS
72
   RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
73
   #endif
74
75
76
   #ifdef HAVE_CGROUP
   CGROUP,
   #endif
77
   LAST_PROCESSFIELD
Hisham Muhammad's avatar
Hisham Muhammad committed
78
79
80
81
82
83
84
85
86
87
} ProcessField;

struct ProcessList_;

typedef struct Process_ {
   Object super;

   struct ProcessList_ *pl;
   bool updated;

Hisham Muhammad's avatar
Hisham Muhammad committed
88
   pid_t pid;
Hisham Muhammad's avatar
Hisham Muhammad committed
89
90
91
92
   char* comm;
   int indent;
   char state;
   bool tag;
Hisham Muhammad's avatar
Hisham Muhammad committed
93
   bool showChildren;
94
   bool show;
Hisham Muhammad's avatar
Hisham Muhammad committed
95
   pid_t ppid;
96
97
98
   unsigned int pgrp;
   unsigned int session;
   unsigned int tty_nr;
Hisham Muhammad's avatar
Hisham Muhammad committed
99
   pid_t tgid;
100
   int tpgid;
Hisham Muhammad's avatar
Hisham Muhammad committed
101
   unsigned long int flags;
102
   #ifdef DEBUG
Hisham Muhammad's avatar
Hisham Muhammad committed
103
104
105
106
   unsigned long int minflt;
   unsigned long int cminflt;
   unsigned long int majflt;
   unsigned long int cmajflt;
107
   #endif
108
109
110
111
   unsigned long long int utime;
   unsigned long long int stime;
   unsigned long long int cutime;
   unsigned long long int cstime;
Hisham Muhammad's avatar
Hisham Muhammad committed
112
113
   long int priority;
   long int nice;
114
   long int nlwp;
Hisham Muhammad's avatar
Hisham Muhammad committed
115
116
   char starttime_show[8];
   time_t starttime_ctime;
117
   #ifdef DEBUG
Hisham Muhammad's avatar
Hisham Muhammad committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
   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;
134
   #endif
Hisham Muhammad's avatar
Hisham Muhammad committed
135
136
137
138
139
140
141
142
143
144
145
146
   int exit_signal;
   int processor;
   int m_size;
   int m_resident;
   int m_share;
   int m_trs;
   int m_drs;
   int m_lrs;
   int m_dt;
   uid_t st_uid;
   float percent_cpu;
   float percent_mem;
147
   char* user;
148
   #ifdef HAVE_OPENVZ
149
   unsigned int ctid;
150
151
   unsigned int vpid;
   #endif
Hisham Muhammad's avatar
Hisham Muhammad committed
152
153
154
   #ifdef HAVE_VSERVER
   unsigned int vxid;
   #endif
155
156
157
158
159
160
161
162
163
164
165
166
167
   #ifdef HAVE_TASKSTATS
   unsigned long long io_rchar;
   unsigned long long io_wchar;
   unsigned long long io_syscr;
   unsigned long long io_syscw;
   unsigned long long io_read_bytes;
   unsigned long long io_write_bytes;
   unsigned long long io_cancelled_write_bytes;
   double io_rate_read_bps;
   unsigned long long io_rate_read_time;
   double io_rate_write_bps;
   unsigned long long io_rate_write_time;   
   #endif
168
169
170
   #ifdef HAVE_CGROUP
   char* cgroup;
   #endif
Hisham Muhammad's avatar
Hisham Muhammad committed
171
172
173
} Process;


174
#ifdef DEBUG
Hisham Muhammad's avatar
Hisham Muhammad committed
175
extern char* PROCESS_CLASS;
176
177
178
#else
#define PROCESS_CLASS NULL
#endif
Hisham Muhammad's avatar
Hisham Muhammad committed
179

Hisham Muhammad's avatar
Hisham Muhammad committed
180
extern const char *Process_fieldNames[];
Hisham Muhammad's avatar
Hisham Muhammad committed
181

Hisham Muhammad's avatar
Hisham Muhammad committed
182
extern const char *Process_fieldTitles[];
183

184
185
186

void Process_getMaxPid();

187
188
189
#define ONE_K 1024
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
Hisham Muhammad's avatar
Hisham Muhammad committed
190
191
192

void Process_delete(Object* cast);

193
194
Process* Process_new(struct ProcessList_ *pl);

Hisham Muhammad's avatar
Hisham Muhammad committed
195
196
void Process_toggleTag(Process* this);

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

199
#ifdef HAVE_HWLOC
200

201
Affinity* Process_getAffinity(Process* this);
202

203
bool Process_setAffinity(Process* this, Affinity* affinity);
204
205
206
207
208
209
210

#elif HAVE_NATIVE_AFFINITY

Affinity* Process_getAffinity(Process* this);

bool Process_setAffinity(Process* this, Affinity* affinity);

Hisham Muhammad's avatar
Hisham Muhammad committed
211
#endif
212

Hisham Muhammad's avatar
Hisham Muhammad committed
213
void Process_sendSignal(Process* this, int sgn);
Hisham Muhammad's avatar
Hisham Muhammad committed
214

215
216
217
int Process_pidCompare(const void* v1, const void* v2);

int Process_compare(const void* v1, const void* v2);
Hisham Muhammad's avatar
Hisham Muhammad committed
218
219

#endif