-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobs.c
More file actions
39 lines (38 loc) · 827 Bytes
/
Copy pathjobs.c
File metadata and controls
39 lines (38 loc) · 827 Bytes
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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
void jobstat(int shellid,char* home_path,char *jobstatus)
{
char *procpath=(char *)malloc(30*sizeof(char));
char *temp_path=(char *)malloc(100*sizeof(char));
sprintf(procpath,"/proc/%d/stat",shellid);
FILE *file;
file=fopen(procpath,"r");
if(!file)
{
perror("Error:");
return;
}
else
{
char *cont=NULL;
char tokens[50][30];
// char *token=(char *)malloc(30*sizeof(char));
size_t len=0;
int args;
if(getline(&cont,&len,file)==-1)
{
perror("Error");
return;
}//==-1 for error
fclose(file);
char *token=strtok(cont," ");
for(args=0;token!=NULL;args++)
{
strcpy(tokens[args],token);
token=strtok(NULL," ");
}
strcpy(jobstatus,tokens[2]);
}
}