-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.c
77 lines (70 loc) · 1.93 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "headers.h"
#include "globals.h"
#include "definitions.h"
#include "pinfo.h"
#include "childproc.h"
void jobs()
{
processDetails *childProcessList = getChildProcessList();
processDetails *process = childProcessList->next;
while (process != NULL)
{
char *status_info = getProcessDetails(process->pid, "State");
char *status = "Running";
if (status_info[0] == 'T' || status_info[0] == 'Z' || status_info[0] == 'X')
{
status = "Stopped";
}
printf("[%d] %s %s [%d]\n", process->jobid, status, process->command, process->pid);
process = process->next;
}
}
void kjob(char **parsedCommand, int parsedLength)
{
if (parsedLength == 3)
{
int jobNum = atoi(parsedCommand[1]);
int signalNum = atoi(parsedCommand[2]);
processDetails *childProcessList = getChildProcessList();
processDetails *process = childProcessList->next;
int found = 0;
while (process != NULL)
{
if (process->jobid == jobNum)
{
found = 1;
break;
}
process = process->next;
}
if (found)
{
if (kill(process->pid, signalNum) != 0)
{
perror("Process cannot be killed");
}
}
else
{
printf("Error: Job id does not exist\n");
}
}
else
{
printf("Unsufficient arguments supplied\n");
}
}
void overkill()
{
processDetails *childProcessList = getChildProcessList();
processDetails *process = childProcessList->next;
while (process != NULL)
{
processDetails *nextProcess = process->next;
if (kill(process->pid, SIGKILL) != 0)
{
perror("Process cannot be killed");
}
process = nextProcess;
}
}