Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following two high level programs that are executed concurrently. Some system level events occurred during the execution of each. Follow the example for

  1. Consider the following two high level programs that are executed concurrently. Some system level events occurred during the execution of each. Follow the example for process state transitions, add the events that occur during execution (in addition to the ones that are given). Instruction: Fill in the events with your answer which are followed by ?. Write your answer after ?. DONT DELETE ?

    Program P:

    {

    read(x);

    compute factorial of x;

    print(x);

    pid = fork();

    if (pid == 0)

    {

    read(y);

    compute factorial of y;

    print(y);

    }

    else /* parent process */

    wait (pid);

    -- while waiting, child processs read (y) is done

    -- while waiting, child processs print (y) is done

    }

    Program Q:

    {

    initialize matrix A using random number generator;

    -- I/O interrupt: Ps read (x) operation is done

    initialize matrix B using random number generator;

    -- I/O interrupt: Ps print (x) operation is done

    create a thread to compute A*B;

    }

    Your Answer

    -- Event: user runs the program ready

    Program P;

    {

    -- Event: scheduled to run running (context switch)

    read (x);

    -- Event: I/O statement blocked

    Switch to execute another process (context switch)

    -- Event: scheduled to run running (context switch)

    compute factorial of x;

    print (x);

    -- Event: ?

    -- Event: ?

    pid = fork ();

    -- Event: system call Blocked

    Switch to kernel mode to handle fork (context switch)

    OS creates the child process, put it in ready queue

    Switch back to run parent process in user mode (context switch)

    if (pid == 0)

    -- Event: Event: scheduled to run childe process running (context switch)

    { read (y);

    -- Event: ?

    -- Event: scheduled to run running (context switch)

    compute factorial of y;

    print (y);

    -- Event: I/O statement blocked

    Before blocked, switch to kernel mode to handle read

    Switch to execute another process (context switch)

    -- Event: scheduled to run running (context switch)

    Child process terminates, switch to another process

    }

    else /* parent process */

    wait (pid);

    -- Event: ?

    -- while waiting, child processs read (y) is done

    -- Event: CPU switches to interrupt handler and put child process in ready state

    -- while waiting, child processs print (y) is done

    -- Event: ?

    }

    -- Event: user runs the program ready

    Program Q;

    {

    -- Event: scheduled to run running (context switch)

    initialize matrix A using random number generator;

    -- I/O interrupt: Ps read (x) operation is done

    -- Event: CPU switches to interrupt handler and put P in ready state

    -- Event: CPU continue to execute the original running process

    initialize matrix B using random number generator;

    -- I/O interrupt: Ps print (x) operation is done

    -- Event: ?

    -- Event: ?

    create a thread to compute A*B;

    -- Event: Nothing, since it is a user level thread

    }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

2. Show the trainees how to do it without saying anything.

Answered: 1 week ago