Øvelse 11


Exercise 1 Processes

Exercise 1.1 Simple process creation

The program created is as follow:


When we executes the program, we see the following:


Explain the value of the PIDs and the return values from fork() - how can one function return two different values?
Because there is two processes when forked. The PID value increment when a new process is spawned.

Explain what happens when a process is forked:
  • What happens to the memory from the parent passed to the child
Both child and parent points to the same memory pages. But when the child process starts to write data, it copy the original memory pages and allocates it into a new place and starts write to it.
  • What is passed to the child process and what is not?
Mutexes conditionals and open files. Though the PID is canged.
  • Why must it be _exit() that is called from within the child and not exit()?
Because exit() leave the whole program.

Exercise 1.2 Single program - multiple processes

The first program is as follow:


The two other programs is:

program2:



program3:




When we executes the program, we see as follow:



Explain what happens when a process is spawned via the exec() function family:
  • What is passed to the "child" process and what is not?
Mutexes, semaphores, conditional and the thread that called fork.

Other threads in the parent is not passed. Either is memory locks and shared memory.
  • What should one be vary about when spawning processes in a security context (in relation to the previous question)?
A security breach could occur because two poccesses have acces to the same memory.

Exercise 2 - Shared Memory

The code is implemented as follow:


Questions to answer:

  • Describe the concept behind shared memory this includes which steps to go through and what to remember from a purely functional point of view.

  1. You have to craete and share memory
  2. You have to read and write the data
  3. You have to clean up when read/write is done
  • Under which circumstances would you consider shared memory a viable solution?
If we have multiole thread that wants to communicate between each other it would be idea lto have share memory this would reduce the reading/writing time however shared memory means that multiple threads has access and could change data when it should not.



Ingen kommentarer:

Send en kommentar