-2

Basically its a question taken form an exam . They are asking to draw the process Tree regards to the question below. I hope someone would like to help and explain me how to track it

  • a) the output of the code above--> The picture I have given below
  • b) who is the first process to print caught signal
  • c)who is the first process to print is ready
  • d) what will happen if we will delete signal function in main()
  • e)what will happen if we will delete sleep(2)

enter image description here

this is the answer to A which also i don't understand .

enter image description here

  • 3
    Don't post code as images – klutt Jun 23 '19 at 13:41
  • 1
    why don't you just run the code and see what happens? – OznOg Jun 23 '19 at 13:51
  • If I don't understand what going on in the first place i would no understand what going on in the "tweaking" questions.Running the code would not give me an explanation.I already have the output in a matter of tree but I need an explanation. –  Jun 23 '19 at 14:00
  • it seems to be time to 'take a meeting' with your instructor (or TA) – user3629249 Jun 23 '19 at 14:39

1 Answers1

2

There are 2 fork calls and no condition on them, thus we must end up with 4 processes (this is the first thing you see on the picture)

What happens in details:

first root process exists.

then it forks so we have process root (1) and child (2) then, another call to fork occurs, and as it is done in both child and root, both processes will fork, thus:

root - fork() ----------- fork() -----
          \                  \--- child (3)
           \--child (2)-- fork() ------
                             \---- child (4)

which is what you have on your picture (obviously, one cannot really predict if 3 will be spawned before 4, thus 4 may be the second root child and 3 the child of 2)

OznOg
  • 4,440
  • 2
  • 26
  • 35