-
Notifications
You must be signed in to change notification settings - Fork 0
/
child_process.c
70 lines (67 loc) · 1.09 KB
/
child_process.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
#include "header.h"
void delete_process(pid_t pid)
{
child_t *target = head;
// 終了するpidの探索
while (1)
{
if (target == NULL)
{
printf("Not found");
exit(EXIT_FAILURE);
}
if (target->pid == pid)
{
break;
}
target = target->next;
}
// delete process
printf("pid %d delete process\n", target->pid);
if (target->pid == head->pid)
{
child_t *new = head->next;
free(head);
head = new;
}
else
{
child_t *new = head;
while (new->next != target)
{
new = new->next;
}
new->next = target->next;
free(target);
target = new;
}
sum_child -= 1;
return;
}
void add_process(pid_t pid, bool background_flag)
{
child_t *target = malloc(1 * sizeof(child_t));
// set pid ID
target->pid = pid;
// FG or BG
if (background_flag == true)
{
target->fg_status = false;
}
else
{
target->fg_status = true;
}
target->next = NULL;
if (sum_child == 0)
{
head = target;
tail = target;
}
else
{
tail->next = target;
tail = target;
}
sum_child += 1;
}