-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLLtest.c
44 lines (34 loc) · 878 Bytes
/
LLtest.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
#include"processLinkedList.c"
#include<sys/types.h>
int main() {
node_t *start = createNode(getpid(), "Start");
setLastNode(start);
fflush(stdout);
pid_t pid = fork();
if (pid == -1) {
printf("\nFailed forking child..");
return -1;
} else if (pid == 0) {
for(int i = 2; i >= 0; i--) {
printf("Counting down: %i\n", i);
fflush(stdout);
sleep(1);
}
exit(0);
} else {
node_t * node = createNode(pid, "Testing");
addNode(node);
node_t *n;
n = start;
printf("Parent PID: %i\n", n->pidData);
printf("Child PID: %i\n", n->next->pidData);
while (n->next != NULL) {
n = n->next;
printf("Process PID: %i\n", n->pidData);
fflush(stdout);
}
// waiting for child to terminate
waitpid(pid, NULL, 0);
return 0;
}
}