Skip to content

Commit

Permalink
Introduce PROCINFO_FIELD_NOT_SET = -9999 macro
Browse files Browse the repository at this point in the history
  • Loading branch information
rfjakob committed Apr 8, 2024
1 parent acda7fb commit 131840d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
13 changes: 7 additions & 6 deletions kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */
};

Expand Down
5 changes: 4 additions & 1 deletion meminfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#define PATH_LEN 256

#include <stdbool.h>
#include "proc_pid.h"
#include <stdbool.h>

typedef struct {
// Values from /proc/meminfo, in KiB
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions proc_pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef PROC_PID_H
#define PROC_PID_H

#include <stdbool.h>

typedef struct {
char state;
int ppid;
Expand Down

0 comments on commit 131840d

Please sign in to comment.