-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.c
55 lines (51 loc) · 1.53 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "headers.h"
void jobs_func()
{
//printf("%d\n",iterator);
/*for(int i = 1; i<iterator;i++)
{
printf("%d ",job_array[i].process_id);
printf("%s \n",job_array[i].process_name);
}*/
//printf("entered job with iterator %d\n", iterator);
int jobid;
// printf("i %d\n",iterator);
for(int i=1;i<iterator;i++)
{
jobid = i;
char filedata[10000],path[10000],*p;
snprintf(path,sizeof(path), "/proc/%d/status" , job_array[i].process_id);
FILE * filePointer;
filePointer = fopen(path,"r");
if(filePointer == NULL)
{
printf("Cannot open the file or directory\n");
}
else
{
while(fgets(filedata,sizeof(filedata),filePointer) != NULL)
{
filedata[strlen(filedata)-1] = '\0';
if(strncmp(filedata,"State:",6) == 0)
{
// printf("sdfghjk\n");
p = filedata + 7;
while(isspace(*p)==1)
{
++p;
}
break;
}
}
if(p[0] == 'S')
{
printf("[%d] Running %s [%d]\n",jobid,job_array[i].process_name,job_array[i].process_id);
}
else if(p[0] == 'T')
{
printf("[%d] Stopped %s [%d]\n",jobid,job_array[i].process_name,job_array[i].process_id);
}
}
fclose(filePointer);
}
}