-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchildproc.c
69 lines (63 loc) · 1.63 KB
/
childproc.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
#include "headers.h"
#include "globals.h"
#include "definitions.h"
// int getProcNum(processDetails *processList)
// {
// int count = 0;
// while (processList->next != NULL)
// {
// count++;
// processList = processList->next;
// }
// return count;
// }
processDetails *getProcNode(int pid, processDetails *processList)
{
int count = 0;
while (processList->next != NULL)
{
processDetails *node = processList->next;
if ((node->pid) == pid)
{
return node;
}
processList = processList->next;
}
return NULL;
}
processDetails *generateProcNode(int pid, char *pname, char *command, int jobid)
{
processDetails *node = (processDetails *)malloc(sizeof(processDetails));
node->pid = pid;
node->pname = pname;
node->command = command;
node->jobid = jobid;
node->next = NULL;
return node;
}
processDetails *addProcNode(int pid, char *pname, char *command, processDetails *processList)
{
processDetails *temp = processList;
while ((temp->next) != NULL)
{
temp = temp->next;
}
processDetails *node = generateProcNode(pid, pname, command, temp->jobid + 1);
temp->next = node;
return node;
}
void deleteProcNode(int pid, processDetails *processList)
{
processDetails *temp = processList;
while (temp->next != NULL)
{
processDetails *node = temp->next;
if (node->pid == pid)
{
temp->next = node->next;
free(node);
break;
}
temp = temp->next;
}
}