-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFORK.h
51 lines (43 loc) · 875 Bytes
/
FORK.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
// c program that perform Fork operation
#include <stdio.h>
#include <unistd.h>
#include <wait.h>
#include <signal.h>
void multiple_process(int number)
{
int count, select, i;
pid_t pid;
printf("\n*********** Select Any Operation *************\n");
printf("[-]1.Create child processes\n[-]2.kill child processes\n[-]3.child processes with IDs\n[-]4.Exit\nEnter your select: ");
while (1)
{
scanf("%d", &select);
switch (select)
{
case 1:
for (count = 0; count < number; count++)
{
if ((pid = fork()) == 0)
{
printf("[+]Child process %d\n", i + 1);
}
}
break;
case 2:
kill(pid, SIGINT);
break;
case 3:
for (i = 0; i < number; i++)
{
if ((pid = fork()) == 0)
{
printf("[+][Clild] pid %d from [parent] pid %d\n", getpid(), getppid());
}
}
break;
case 4:
exit(0);
break;
}
}
}