Question

For the purposes of this assignment, the Process Control Blocks (PCB) are implementation as follows: • PCBs are implemented a

Your program requires three functions: create(p) This function creates a child process of process p by performing the followi

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I try my best.

#include <iostream>

#include <unistd.h>

using namespace std;

int main()

{

    int a[10] = { 2, 4, 6, 7, 9, 0, 1, 5, 8, 3 };

    int n1, n2, i, j, key, c, temp;

    n1 = fork();

    n2 = fork();

    if (n1 > 0 && n2 > 0) {

        int c = 0;

        cout << "Parent process :" << endl;

  key = 7;

        cout << "the key to be searched is " << key << endl;

        for (i = 0; i < 10; i++) {

            if (a[i] == key)

                 c++;

        }

         cout << "the frequency of " << key << " is " << c << endl;

    }

         else if (n1 == 0 && n2 > 0) {

        cout << "1st child process :" << endl;

        for (i = 0; i < 10; i++) {

            for (j = 0; j < 9; j++) {

                if (a[j] > a[j + 1]) {

                    temp = a[j];

                    a[j] = a[j + 1];

                    a[j + 1] = temp;

                }

            }

        }

        cout << "the sorted array is" << endl;

        for (i = 0; i < 10; i++) {

            cout << a[i] << " ";

        }

        cout << endl;

    }

    else if (n1 > 0 && n2 == 0) {

        int f = 0;

        cout << "2nd child process :" << endl;

        for (i = 0; i < 10; i++) {

  if (a[i] % 2 == 0) {

                f++;

            }

        }

        cout << " Total even no are: " << f << " ";

        cout << endl;

    }

        else if (n1 == 0 && n2 == 0) {

        cout << "3rd child process :" << endl;

        int sum = 0;

                for (i = 0; i < 10; i++) {

            sum = sum + a[i];

        }

        cout << "the sum is :" << sum << endl;

    }

    return 0;

}

#include<iostream>

#include<process.h>

using namespace std;

int main()

{

int a[50],x,n,i,j,b[50];

cout<<"How many elements of Array you want to create?";

cin>>n;

cout<<"\nEnter elements of Array\n";

for(i=0;i<n;++i)

cin>>a[i];

cout<<"\nEnter element to delete:";

cin>>x;

for(i=0,j=0;i<n;++i)

{

if(a[i]!=x)

b[j++]=a[i];

}

if(j==n)

{

cout<<"\nSoory!!!Element is not in the Array";

exit(0);

}

else

{

cout<<"\nNew Array is ";

for(i=0;i<j;i++)

cout<<b[i]<<" ";

}

return 0;

}

Create:

To create a replacement kid method, the parent method calls the produce primitive with the input parameters: initial central processor state s0, initial main memory m0, and priority pi. The m0 field may well be a reasonably complicated structure, for instance, encompassing real and virtual space for programs, data, and stacks. The initial standing are going to be prepared s—ready as a result of the new method ought to be in position to proceed while not anticipating any resources and suspended as a result of it should be fascinating to form a method well before its activation. The Create primitive returns the distinctive id (pid) of the new method as associate output parameter.

The first preparation creates a new instance of the process descriptor (Fig. 4-5) with p pointing to that example. The next two instructions create and assign a unique ID to the new technique. Subsequent instructions fill the individual fields of the descriptor using given parameters. We assume that any procedure is ready to attain the pointer to its own descriptor, either via an agreed-upon register or through a kernel call; the call self designates this pointer. Create adds p to self’s child listing and inserts p on the Ready List RL. The initial assets—here only essential memory—are generally shared assets for the new manner and, typically, must be a subset of those belonging to the parent technique. The discern might also proportion any of its assets with different child approaches in a similar manner. The created method, in turn, can share its sources with any youngsters it creates. At the end, the scheduler is called to choose the system to run subsequent.

Create(s0, m0, pi, pid) {

p = Get New PCB();

pid= Get New PID();

p -> ID = pid ;

p -> CPU State = s0;

p -> Memory = m0;

p -> Priority = pi;

p -> Status.Type = ‘ready s’;

p -> Status.List = RL;

p -> Creation Tree.Parent = self;

p -> Creation Tree.Child= NULL;

insert(self -> Creation Tree.Child, p);

insert(RL, p); Scheduler(); }

Destroy:

For destroying a method, identical alternatives square measure attainable as for the Suspend operation— we can either take away one method (a descendant) or take away that method and every one of its descendants. If the primary policy is chosen, the method hierarchy will simply fragment, potentially departure isolated processes within the system with no management over their behavior. We thus need that Destroy removes the named method and every one its descendants.The operate is invoked by the decision Destroy(pid), wherever PID is that the ID of the foundation process of the subtree to be removed. The procedure obtains the pointer to the current method and calls the routine Kill Tree(p), that recursively eliminates the complete tree. It calls Kill Tree(q) for every method Q on the present method kid list. for every method within the tree, Kill Tree take as follows. If the method is presently running, it's stopped by interrupting its computer hardware and marking it as free. The procedure then removes the method from the list pointed to by standing.List. this is often the prepared list if the method was running or ready, and otherwise a roster related to the resource upon that the method was blocked. Next, the procedure releases all resources presently allotted to the method and closes all files opened by the method. This doubtless unblocks alternative processes waiting for the free resources. Finally, the method descriptor is deleted and its area returned to the system. once the complete tree is eliminated and Kill Tree(p) returns to Destroy(pid), the method hardware is termed to work out that process(es) ought to be running next. this could embody the present process—the one World Health Organization issued the Destroy command—and any variety of processes which will became unblocked as a result of the Destroy operation.

Destroy(pid) { p = Get PCB(pid);

Kill Tree(p); Scheduler();

}

Kill Tree(p) { for (each q in p -> Creation Tree.Child) Kill Tree(q);

if (p -> Status.Type == ‘running’) { cpu = p -> Processor ID;

Interrupt(cpu); }

Remove(p -> Status.List, p); Release all(p -> Memory);

Release all(p -> Other Resources);

Close all(p -> Open Files); Delete PCB(p);

}

Add a comment
Know the answer?
Add Answer to:
For the purposes of this assignment, the Process Control Blocks (PCB) are implementation as follows: •...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • EMULATE A PROCESS CONTROL BLOCK In this assignment you will use Java, Python or C++ to...

    EMULATE A PROCESS CONTROL BLOCK In this assignment you will use Java, Python or C++ to create a process control block. All objects described aren’t provided, you will create them. You can divide up this code into separate files or put all code in one file. Proper documentation is essential, if there are no comments 5% of the total grade will be deducted. The process control block object PCB should have the following fields: ID: a unique ID for this...

  • 1. Solve synchronization problems inherent in inter-process communication and multi-threaded applications.

    1. Process control system calls: The demonstration of fork, execve and wait system calls along with zombie and orphan states.a. Implement the C program in which main program accepts the integers to besorted. Main program uses the fork system call to create a new process called a child process. Parent process sorts the integers using merge sort and waits for child process using wait system call to sort the integers using quick sort. Also demonstrate zombie and orphan states.b. Implement...

  • State transition diagram used for operating system management of the Process Control Block has the following...

    State transition diagram used for operating system management of the Process Control Block has the following states A New (Create)– In this step, process is about to be created but not yet created, it is the program which is present in secondary memory that will be picked up by OS to create the process. Ready -> Ready to run. After creation of a process, the process enters the ready state i.e. the process is loaded into the main memory. The...

  • In this assignment, you will write one (1) medium size C program. The program needs to...

    In this assignment, you will write one (1) medium size C program. The program needs to be structured using multiple functions, i.e., you are required to organize your code into distinct logical units. The following set of instructions provide the specific requirements for the program. Make sure to test thoroughly before submitting. Write   a   program,   named   program1.c,   that   reads   and   processes   employee   records   (data   about   an   employee).   Each   employee   record   must   be   stored   using   a   struct   that   contains   the   following  ...

  • //bubble sort implementation// Fig 6.15 with simplified convention for the for loop. #define _CRT...

    //bubble sort implementation// Fig 6.15 with simplified convention for the for loop. #define _CRT_SECURE_NO_WARNINGS //for windows os only #include <stdio.h> #include <stdlib.h> // Fig. 6.15: fig06_15.c // Sorting an array's values into ascending order. #include <stdio.h> #define SIZE 10 // function main begins program execution int main(void) {    // initialize a    int a[SIZE] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };    printf("Data items in original order");    // output original array    for (int i = 0;...

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In t...

    c++ PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...

  • Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as...

    Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...

  • C Program Assignment: 2-Add comments to your program to full document it by describing the most...

    C Program Assignment: 2-Add comments to your program to full document it by describing the most important processes. 3-Your variables names should be very friendly. This means that the names should have meaning related to what they are storing. Example: Instead of naming the variable that stores the hours worked for an employee in a variable called ‘x’ you should name it HoursWorked. 5-Submit your .c program (note that I only need your source code and not all files that...

  • #include<iostream> using namespace std; class TNode { public: int val; TNode(){} TNode(int v){val = v;} TNode...

    #include<iostream> using namespace std; class TNode { public: int val; TNode(){} TNode(int v){val = v;} TNode * left; TNode * right; TNode * parent; }; class BTree { public: //constructors and destructor BTree(); BTree(TNode *r);// initialize BTree with the root r. r is the only node. BTree(const BTree & t); // copy constructor BTree(const int *p, const int n);// similar to the copy constructor, but your input is of the array form. // input is given an array that denotes...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT