I3ISU_Opgave12

=Exercise 1 - Processes= In this exercise, we are going to work with processes.

Exercise 1.1 - Simple Process Creation
In this exercise, we create a child process, identify the parent and the child process, and then shutdown the child again.

code format="cpp" using namespace std;
 * 1) include
 * 2) include 
 * 3) include 
 * 4) include 

int main {   pid_t pid; pid = fork;

if(pid == 0) {       cout << "Hi! I am the child process. fork Value: " << pid << ", pid value: " << getpid << endl; _exit(2); }   else {       cout << "Hi! I am the parent process. fork Value: " << pid << ", pid value: " << getpid << endl; wait(NULL); }

return 0; } code When running the program we get the following output: code stud@GoldenImage:~$ ./main Hi! I am the parent process. fork Value: 3622, pid value: 3621 Hi! I am the child process. fork Value: 0, pid value: 3622

code
 * What happens to the memory from the parent passed to the child?**
 * What is passed to the child process and what is not?**
 * Why must it be _exit that is called from within the child and not exit?**

Exercise 1.2 - Simple program, multiple processes
Here we create a simple program, that spawns 2 processes, and wait for them to finish their job, then terminate. code format="cpp" using namespace std;
 * 1) include
 * 2) include 
 * 3) include 
 * 4) include 

int main {	pid_t pid1, pid2; pid1 = fork;

if(pid1 == 0) {		for(int i = 0; i < 5; i++) {			cout << "Tick" << endl; sleep(1); }		_exit(2); }	else {		pid2 = fork;

if(pid2 == 0) {			for(int i = 0; i < 8; i++) {			     cout << "Tock" << endl; sleep(1); }			_exit(2); }		else wait(NULL);

wait(NULL); cout << "Done" << endl; }

return 0; } code When running this program, we get the following output: code stud@GoldenImage:~$ ./main Tock Tick Tock Tick Tock Tick Tick Tock Tick Tock Tock Tock Tock Done

code

=Exercise 2 - Shared Memory= In this exercise, are to going to work with shared memory, including sending data, mutexes and conditionals.
 * What is passed to the "child" and what is not?**
 * What should one be vary about when spawning processes in a security context?**