processes

This commit is contained in:
gandc 2025-02-23 01:00:54 +03:00
parent bbedbefe62
commit 573887adce
Signed by: gandc
GPG Key ID: 9F77B03D43C42CB4
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,16 @@
#include "processes.h"
#include <stdio.h>
#include <stdlib.h>
void list_processes(FILE *output) {
FILE *fp = popen("ps -eo pid,comm --sort=pid", "r");
if (fp == NULL) {
fprintf(output, "Error opening process list\n");
return;
}
char line[256];
while (fgets(line, sizeof(line), fp) != NULL) {
fprintf(output, "%s", line);
}
pclose(fp);
}

View File

@ -0,0 +1,5 @@
#ifndef PROCESSES_H
#define PROCESSES_H
#include <stdio.h>
void list_processes(FILE *output);
#endif