Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g
LDFLAGS = -lncurses
OS = $(shell uname -s)

TARGET = process_manager
SRCS = main.c process_list.c ui.c
SRCS = main.c ui.c

ifeq ($(OS),Darwin)
SRCS += process_list_macos.c
CFLAGS += -D__APPLE__
else ifeq ($(OS),Linux)
SRCS += process_list_linux.c
else
$(error Unsupported OS: $(OS))
endif

OBJS = $(SRCS:.c=.o)

all: $(TARGET)
Expand Down
4 changes: 2 additions & 2 deletions process_list.c → process_list_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ static int is_numeric(const char *str) {
static long unsigned int get_memory_usage(const char *pid_str) {
char path[256];
snprintf(path, sizeof(path), "/proc/%s/status", pid_str);

FILE *f = fopen(path, "r");
if (!f) return 0; // process probably died

char line[256];
long unsigned int mem = 0;

while (fgets(line, sizeof(line), f)) {
if (strncmp(line, "VmRSS:", 6) == 0) {
sscanf(line, "VmRSS: %lu", &mem);
Expand Down
Loading