-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.c
executable file
·31 lines (25 loc) · 856 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
#include "headers.h"
void alljobs()
{
for(ll i=1; i<=job_count; i++)
{
ll pid=job_arr[i].pid;
char name[10000],file[10000],status,s[100000];
strcpy(name,job_arr[i].name);
sprintf(file, "/proc/%lld/stat",pid);
FILE *fd;
fd=fopen(file,"r");
if(fd<0)
perror("Error: no such process exists\n");
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 %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d", &status);
fclose(fd);
}
if(status=='T')
strcpy(s,"Stopped");
else
strcpy(s,"Running");
printf("[%lld] %s %s [%lld]\n",i, s, name,pid);
}
}