-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs.c
33 lines (30 loc) · 816 Bytes
/
jobs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "header.h"
void jobs()
{
char *stat = malloc(sizeof(char) * 100);
for (int i=0; i < job_count; i++)
{
sprintf(stat, "/proc/%d/status", jobarray[i].PID);
FILE *f;
if (!(f = fopen(stat, "r")))
continue;
// perror("job exited");
else {
char *info = find_line(stat, 3);
char *temp = info;
info = strtok(info, " :\n\t\r");
info = strtok(NULL, " :\n\t\r");
if(info[0] == 'T')
{
strcpy(info, "Stopped");
}
else
{
strcpy(info, "Running");
}
printf("[%d] %s %s [%d]\n", i+1, info, jobarray[i].job_name, jobarray[i].PID);
free(temp);
}
}
free(stat);
}