+ free(buf);
+ }
+}
+
+#define GID_ENTRY "Gid:\t"
+void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
+#define GIDNOTFOUND "Can't find the process real gid in '%s'"
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/status", obj->data.s);
+ strcpy(obj->data.s, buf);
+ free(buf);
+ buf = readfile(obj->data.s, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, GID_ENTRY);
+ if(begin != NULL) {
+ begin += strlen(GID_ENTRY);
+ end = strchr(begin, '\t');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(GIDNOTFOUND, obj->data.s);
+ }
+ free(buf);
+ }
+}
+
+void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
+#define EGIDNOTFOUND "Can't find the process effective gid in '%s'"
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/status", obj->data.s);
+ strcpy(obj->data.s, buf);
+ free(buf);
+ buf = readfile(obj->data.s, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, GID_ENTRY);
+ if(begin != NULL) {
+ begin = strchr(begin, '\t'); begin++;
+ begin = strchr(begin, '\t'); begin++;
+ end = strchr(begin, '\t');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(EGIDNOTFOUND, obj->data.s);
+ }
+ free(buf);
+ }
+}
+
+void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
+#define SGIDNOTFOUND "Can't find the process saved set gid in '%s'"
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/status", obj->data.s);
+ strcpy(obj->data.s, buf);
+ free(buf);
+ buf = readfile(obj->data.s, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, GID_ENTRY);
+ if(begin != NULL) {
+ begin = strchr(begin, '\t'); begin++;
+ begin = strchr(begin, '\t'); begin++;
+ begin = strchr(begin, '\t'); begin++;
+ end = strchr(begin, '\t');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(SGIDNOTFOUND, obj->data.s);
+ }
+ free(buf);
+ }
+}
+
+void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
+#define FSGIDNOTFOUND "Can't find the process file system gid in '%s'"
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/status", obj->data.s);
+ strcpy(obj->data.s, buf);
+ free(buf);
+ buf = readfile(obj->data.s, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, GID_ENTRY);
+ if(begin != NULL) {
+ begin = strchr(begin, '\t'); begin++;
+ begin = strchr(begin, '\t'); begin++;
+ begin = strchr(begin, '\t'); begin++;
+ begin = strchr(begin, '\t'); begin++;
+ end = strchr(begin, '\n');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(FSGIDNOTFOUND, obj->data.s);
+ }
+ free(buf);
+ }
+}
+
+void internal_print_pid_vm(char* pid, char *p, int p_max_size, const char* entry, const char* errorstring) {
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/status", pid);
+ strcpy(pid, buf);
+ free(buf);
+ buf = readfile(pid, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, entry);
+ if(begin != NULL) {
+ begin += strlen(entry);
+ while(*begin == '\t' || *begin == ' ') {
+ begin++;
+ }
+ end = strchr(begin, '\n');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(errorstring, pid);
+ }
+ free(buf);
+ }
+}
+
+void print_pid_vmpeak(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmPeak:\t", "Can't find the process peak virtual memory size in '%s'");
+}
+
+void print_pid_vmsize(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmSize:\t", "Can't find the process virtual memory size in '%s'");
+}
+
+void print_pid_vmlck(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmLck:\t", "Can't find the process locked memory size in '%s'");
+}
+
+void print_pid_vmhwm(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmHWM:\t", "Can't find the process peak resident set size in '%s'");
+}
+
+void print_pid_vmrss(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmHWM:\t", "Can't find the process resident set size in '%s'");
+}
+
+void print_pid_vmdata(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmData:\t", "Can't find the process data segment size in '%s'");
+}
+
+void print_pid_vmstk(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmData:\t", "Can't find the process stack segment size in '%s'");
+}
+
+void print_pid_vmexe(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmData:\t", "Can't find the process text segment size in '%s'");
+}
+
+void print_pid_vmlib(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmLib:\t", "Can't find the process shared library code size in '%s'");
+}
+
+void print_pid_vmpte(struct text_object *obj, char *p, int p_max_size) {
+ internal_print_pid_vm(obj->data.s, p, p_max_size, "VmPTE:\t", "Can't find the process page table entries size in '%s'");
+}
+
+#define READ_ENTRY "read_bytes: "
+#define READNOTFOUND "Can't find the amount of bytes read in '%s'"
+void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/io", obj->data.s);
+ strcpy(obj->data.s, buf);
+ free(buf);
+ buf = readfile(obj->data.s, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, READ_ENTRY);
+ if(begin != NULL) {
+ end = strchr(begin, '\n');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(READNOTFOUND, obj->data.s);
+ }
+ free(buf);
+ }
+}
+
+#define WRITE_ENTRY "write_bytes: "
+#define WRITENOTFOUND "Can't find the amount of bytes written in '%s'"
+void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
+ char *begin, *end, *buf = NULL;
+ int bytes_read;
+
+ asprintf(&buf, PROCDIR "/%s/io", obj->data.s);
+ strcpy(obj->data.s, buf);
+ free(buf);
+ buf = readfile(obj->data.s, &bytes_read, 1);
+ if(buf != NULL) {
+ begin = strstr(buf, WRITE_ENTRY);
+ if(begin != NULL) {
+ end = strchr(begin, '\n');
+ if(end != NULL) {
+ *(end) = 0;
+ }
+ snprintf(p, p_max_size, "%s", begin);
+ } else {
+ NORM_ERR(WRITENOTFOUND, obj->data.s);
+ }
+ free(buf);