-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_signals.cpp
More file actions
59 lines (53 loc) · 1.3 KB
/
Copy pathprocess_signals.cpp
File metadata and controls
59 lines (53 loc) · 1.3 KB
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
/**
*Originally created for testing purpose. Made by Sombaran Gupta.
* For any further query email me @ guptasombaran@yahoo.com
* Created for Linux environment
*/
#include "process_signals.hpp"
void process_variation_1(void) {
pid_t pid;
printf("The base pid = %d \n",getpid());
pid = fork();
if(pid != NULL)
{
printf("This is parent process = %d \n",getpid());
printf("This is the child created from the parent process = %d \n",pid);
}
else
{
printf("This is child process = %d \n",getpid());
}
}
void process_variation_2(void ) {
pid_t my_pid,parent_pid,child_pid;
my_pid = getpid();
parent_pid = getppid();
child_pid = fork();
printf("Parent: my parent's pid = %d \n", parent_pid);
printf("Parent: my pid = %d \n", my_pid);
printf("Parent: my child's pid = %d \n", child_pid);
}
void myhandle(int mysig) {
printf("Thats my handle: %d\n", mysig);
}
void signals_variations_3(void) {
int i=0;
signal(SIGTERM,myhandle);
while(1)
{
printf("i=%d\n", i);
i++;
sleep(1);
}
}
int main(void) {
std::cout << "PID inside main: " << getpid() << std::endl;
std::thread var_1(process_variation_1);
var_1.join();
std::thread var_2(process_variation_2);
var_2.join();
std::cout << "Signals Begins HERE....." << std::endl;
std::thread var_3(signals_variations_3);
var_3.join();
return (0);
}