diff --git a/kill.c b/kill.c index bf51b7d..d4746f7 100644 --- a/kill.c +++ b/kill.c @@ -391,6 +391,8 @@ bool is_larger(const poll_loop_args_t* args, const procinfo_t* victim, procinfo_ return true; } +// Fill the fields in `cur` that are not required for the kill decision. +// Used to log details about the selected process. void fill_informative_fields(procinfo_t* cur) { if (strlen(cur->name) == 0) { @@ -440,13 +442,12 @@ procinfo_t find_largest_process(const poll_loop_args_t* args) debug_print_procinfo_header(); - const int field_not_set = -9999; // placeholder value const procinfo_t empty_procinfo = { - .pid = field_not_set, - .uid = field_not_set, - .badness = field_not_set, - .oom_score_adj = field_not_set, - .VmRSSkiB = field_not_set, + .pid = PROCINFO_FIELD_NOT_SET, + .uid = PROCINFO_FIELD_NOT_SET, + .badness = PROCINFO_FIELD_NOT_SET, + .oom_score_adj = PROCINFO_FIELD_NOT_SET, + .VmRSSkiB = PROCINFO_FIELD_NOT_SET, /* omitted fields are set to zero */ }; diff --git a/meminfo.h b/meminfo.h index 7dd1b22..cf7945c 100644 --- a/meminfo.h +++ b/meminfo.h @@ -4,8 +4,8 @@ #define PATH_LEN 256 -#include #include "proc_pid.h" +#include typedef struct { // Values from /proc/meminfo, in KiB @@ -34,6 +34,9 @@ typedef struct procinfo { char cmdline[PATH_LEN]; } procinfo_t; +// placeholder value for numeric fields +#define PROCINFO_FIELD_NOT_SET -9999 + meminfo_t parse_meminfo(); bool is_alive(int pid); void print_mem_stats(int (*out_func)(const char* fmt, ...), const meminfo_t m); diff --git a/proc_pid.h b/proc_pid.h index 97122e1..dbef9d4 100644 --- a/proc_pid.h +++ b/proc_pid.h @@ -2,6 +2,8 @@ #ifndef PROC_PID_H #define PROC_PID_H +#include + typedef struct { char state; int ppid;