Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey, I need some help with this coding question this is what I have so far. This is my homework question problem below here. An

Hey, I need some help with this coding question this is what I have so far.

This is my homework question problem below here.

An operating systems pid manager is responsible for managing process identifiers. When a process is first created, it is assigned a unique pid by the pid manager. The pid is returned to the pid manager when the process completes execution, and the manager may later reassign this pid. Process identifiers must be unique; no two active processes may have the same pid.

Use the following constants to identify the range of possible pid values:

#define MIN_PID 300 #define MAX_PID 5000

You may use any data structure of your choice to represent the availability of process identifiers. One strategy is to adopt what Linux has done and use a bitmap in which a value of 0 at position i indicates that a process id of value i is available and a value of 1 indicates that the process id is currently in use.

Implement the following API for obtaining and releasing a pid:

  • int allocate_map(void) Creates and initializes a data structure for representing pids; returns -1 if unsuccessful and 1 if successful
  • int allocate_pid(void) Allocates and returns a pid; returns -1 if if unable to allocate a pid (all pids are in use)
  • void release_pid(int_pid) Releases a pid.

THIS IS MY CODE IN JAVA BE LOW HERE.

import java.io.*;

import java.util.HashMap;

public class Pid_manager {

//constants

final static int MIN_PID = 300;

final static int MAX_PID = 5000;

HashMap pid_map;

public static void main(String[] args) {

int pid = 0;

Pid_manager process_man = new Pid_manager();

process_man.allocate_map();

process_man.allocate_pid();

process_man.release_pid();

}

/*

* build a data structure in this method

* lookup or read run time O(1)

* link list N

* stack N

* Q n

* tree n

* Array O(1)

* Graph n

* Arraylist O(1)

* Map key, value O(1)*/

public int allocate_map() {

pid_map = new HashMap ( MAX_PID-MIN_PID +1 );

for(int i = MIN_PID; i <= MAX_PID; i++) {

pid_map.put(i, 0);

}

return 1;

}

public int allocate_pid(int pids) {

for(int i = MIN_PID; i <= MAX_PID; i++) {

if(pid_map.get(i) ==0) {

return i;

}

}

return -1;

}

public void release_pid(int pid){

//release a pid

// print the pid here

pid_map.put(pid, 0);

}

}

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions