-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjobs.c
More file actions
40 lines (38 loc) · 1.16 KB
/
jobs.c
File metadata and controls
40 lines (38 loc) · 1.16 KB
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
34
35
36
37
38
39
40
#include "headers.h"
void print_jobs()
{
int i;
int j = 1;
for (i = 1; i <= back_count; i++)
{
if (back[i].is_back == 1)
{
char stat[1000];
char status;
int p;
long unsigned mem;
char str[10];
sprintf(str, "%d", back[i].pid);
strcpy(stat, "/proc/");
strcat(stat, str);
strcat(stat, "/stat");
FILE *fd;
if ((fd = fopen(stat, "r")) == NULL)
{
printf("[%d] %s %s [%d]\n", j, "Done", back[i].name, back[i].pid);
}
else
{
fscanf(fd, "%d %*s %c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %lu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d", &p, &status, &mem);
fclose(fd);
printf("[%d] ", j);
if (status == 'T')
printf("%s ", "Stopped");
else
printf("%s ", "Running");
printf("%s [%d]\n", back[i].name, back[i].pid);
}
j++;
}
}
}