forked from hamon-in/cpslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pslib.h
242 lines (206 loc) · 4.27 KB
/
pslib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#ifndef __pslib_linux_h
#define __pslib_linux_h
enum proc_status {
STATUS_RUNNING,
STATUS_SLEEPING,
STATUS_DISK_SLEEP,
STATUS_STOPPED,
STATUS_TRACING_STOP,
STATUS_ZOMBIE,
STATUS_DEAD,
STATUS_WAKE_KILL,
STATUS_WAKING,
STATUS_IDLE,
STATUS_LOCKED,
STATUS_WAITING
};
enum ioprio_class {
IOPRIO_CLASS_NONE,
IOPRIO_CLASS_RT,
IOPRIO_CLASS_BE,
IOPRIO_CLASS_IDLE
};
enum rlimit {
RLIMIT_INFINITY,
RLIMIT_AS,
RLIMIT_CORE,
RLIMIT_CPU,
RLIMIT_DATA,
RLIMIT_FSIZE,
RLIMIT_LOCKS,
RLIMIT_MEMLOCK,
RLIMIT_MSGQUEUE,
RLIMIT_NICE,
RLIMIT_NOFILE,
RLIMIT_NPROC,
RLIMIT_RSS,
RLIMIT_RTPRIO,
RLIMIT_RTTIME,
RLIMIT_SIGPENDING,
RLIMIT_STACK
};
enum con_status {
ESTABLISHED,
SYN_SENT,
SYN_RECV,
FIN_WAIT1,
FIN_WAIT2,
TIME_WAIT,
CLOSE,
CLOSE_WAIT,
LAST_ACK,
LISTEN,
CLOSING,
NONE,
DELETE_TCB,
IDLE,
BOUND
};
enum proc_priority {
ABOVE_NORMAL_PRIORITY_CLASS,
BELOW_NORMAL_PRIORITY_CLASS,
HIGH_PRIORITY_CLASS,
IDLE_PRIORITY_CLASS,
NORMAL_PRIORITY_CLASS,
REALTIME_PRIORITY_CLASS
};
typedef struct {
unsigned long total;
unsigned long used;
unsigned long free;
float percent;
} DiskUsage;
typedef struct {
char *device;
char *mountpoint;
char *fstype;
char *opts;
} DiskPartition; /* TBD: Pluralise */
typedef struct {
int nitems;
DiskPartition *partitions;
} DiskPartitionInfo;
typedef struct {
char *name;
unsigned long readbytes;
unsigned long writebytes;
unsigned long reads;
unsigned long writes;
unsigned long readtime;
unsigned long writetime;
} DiskIOCounters;
typedef struct {
int nitems;
DiskIOCounters *iocounters;
} DiskIOCounterInfo;
typedef struct {
char * name;
unsigned long bytes_sent;
unsigned long bytes_recv;
unsigned long packets_sent;
unsigned long packets_recv;
unsigned long errin;
unsigned long errout;
unsigned long dropin;
unsigned long dropout;
} NetIOCounters;
typedef struct {
int nitems;
NetIOCounters *iocounters;
} NetIOCounterInfo;
typedef struct {
char *username;
char *tty;
char *hostname;
float tstamp;
} Users;
typedef struct {
int nitems;
Users *users;
} UsersInfo;
typedef struct {
unsigned long total;
unsigned long available;
float percent;
unsigned long used;
unsigned long free;
unsigned long active;
unsigned long inactive;
unsigned long buffers;
unsigned long cached;
} VmemInfo;
typedef struct {
unsigned long total;
unsigned long used;
unsigned long free;
float percent;
unsigned long sin;
unsigned long sout;
} SwapMem;
typedef struct {
double user;
double system;
double idle;
double nice;
double iowait;
double irq;
double softirq;
double steal;
double guest;
double guest_nice;
} CpuTimes;
typedef struct {
unsigned int pid;
unsigned int ppid;
char *name;
char *exe;
char *cmdline;
unsigned long create_time;
unsigned int uid;
unsigned int euid;
unsigned int suid;
unsigned int gid;
unsigned int egid;
unsigned int sgid;
char *username;
char *terminal;
// char *cwd
//unsigned int nice;
// ioprio_class ionice;
} Process;
//*Process process_get_parent();
//proc_status process_get_status();
//rlimit process_get_rlimit();
//int process_io_counters();
//int process_num_ctx_switches();
//int process_num_fds();
//int num_handles();
//int num_threads();
int disk_usage(char [], DiskUsage *);
DiskPartitionInfo *disk_partitions();
DiskPartitionInfo *disk_partitions_phys();
//DiskPartitionInfo *disk_partitions_physical(); ?
void free_disk_partition_info(DiskPartitionInfo *);
DiskIOCounterInfo *disk_io_counters();
void free_disk_iocounter_info(DiskIOCounterInfo *);
//DiskIOCounterInfo *disk_io_counters_per_disk(); ?
NetIOCounterInfo *net_io_counters();
//NetIOCounterInfo *net_io_counters_per_nic(); ?
void free_net_iocounter_info(NetIOCounterInfo *);
UsersInfo *get_users();
void free_users_info(UsersInfo *);
unsigned long int get_boot_time();
int virtual_memory(VmemInfo *);
int swap_memory(SwapMem *);
int cpu_times(CpuTimes *);
int cpu_times_per_cpu(CpuTimes **);
int cpu_times_percent(CpuTimes *);
int cpu_times_percent_per_cpu(CpuTimes **);
double cpu_percent();
int cpu_percent_per_cpu(double **);
int cpu_count(int);
Process *get_process(unsigned int);
void free_process(Process *);
#endif
// disk_io_counters_per_disk
// net_io_counters_per_nic