-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobs.c
More file actions
53 lines (50 loc) · 1.36 KB
/
jobs.c
File metadata and controls
53 lines (50 loc) · 1.36 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
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "headers.h"
void jobs_func()
{
long long int i,j,k,fd_file,job_cnt=0;
char file[10000],pid_str[100],state[100];
for(i=0;i<job_seq_no;i++)
{
if(jobs[i].status==1)
{
char file_path[1000]="/proc/";
sprintf(pid_str,"%d",jobs[i].pid);
strcat(file_path,pid_str);
strcat(file_path,"/stat");
fd_file = open(file_path,O_RDONLY);
if(fd_file<0)
{
jobs[i].status=0;
}
else
{
job_cnt+=1;
read(fd_file,file,10000);
j=0;
char * token = strtok(file," ");
while(token!=NULL)
{
token = strtok(NULL," ");
j++;
// printf(":: %s\n",token);
if(j==2)
break;
}
if(strcmp(token,"T")==0)
{
strcpy(state,"Stopped");
}
else
{
// printf("%s",token);
strcpy(state,"Running");
}
printf("[%lld] %s %s [%d]\n",i,state,jobs[i].command,jobs[i].pid);
}
}
}
if(job_cnt==0)
{
printf("No jobs are running currently\n");
}
}