-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.h
62 lines (58 loc) · 2.07 KB
/
jobs.h
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
56
57
58
59
60
61
62
#include "headers.h"
#include "global.h"
void jobs(){
int flagr = 0;
int flags = 0;
int lineNumber = 1;
for(int i = 1 ; i < argumentNumber ; i++){
if(argumentInput[i][0] == '-'){
if(argumentInput[i][1] == 'r'){
flagr = 1;
}
else if(argumentInput[i][1] == 's'){
flags = 1;
}
else{
printf("Not valid flag for jobs.\n");
}
}
}
for(int i = 0; i < processCommand ; i++){
if(getpgid(processesPID[i]) > 0){
char* processFile = (char *)malloc(VARIABLE_LENGTH * sizeof(char));
strcat(processFile, "/proc/");
char stringPID[256];
int intPID = processesPID[i];
int place = 0;
char** sepratedValues = (char **)malloc(VARIABLE_LENGTH*sizeof(char *));
char line[VARIABLE_LENGTH];
char* tokenized;
while(intPID > 0){
stringPID[place] = 48 + intPID%10;
intPID/=10;
place++;
}
for(int a = 0; a < place/2 ; a++){
char temp = stringPID[place - a - 1];
stringPID[place - a - 1] = stringPID[a];
stringPID[a] = temp;
}
stringPID[place] = '\0';
strcat(processFile, stringPID);
strcat(processFile, "/stat");
FILE *reader = fopen(processFile, "r");
fgets(line, VARIABLE_LENGTH, reader);
int k = 0;
tokenized = strtok(line, " ");
while(tokenized!=NULL){
sepratedValues[k] = tokenized;
tokenized = strtok(NULL, " ");
k++;
}
if (strcmp(sepratedValues[2], "T") == 0 && (flags || (!flags && !flagr)))
printf("[%d] Stopped %s [%d]\n", i + 1, processesNames[i], processesPID[i]);
else if(flagr || (!flagr && !flags))
printf("[%d] Running %s [%d]\n", i + 1, processesNames[i], processesPID[i]);
}
}
}