Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming. Please don't use any previous chegg solutions, if there are any, if you do I may be forced to down vote the solution

C programming. Please don't use any previous chegg solutions, if there are any, if you do I may be forced to down vote the solution so please provide an original answer. Please provide the code for the program file (.c), and the code for any input files created for testing purposes. Please include commenting with your code.

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.

Use the following constants to identify the range of possible pid values(for testing these values may be changed, your code must be able to deal with the changes):

#define MIN PID 300 #define MAX PID 5000

You must use a linked list.

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, 1 if successful

int allocate pid(void) - Allocates and returns a pid; returns 1 if unable to allocate a pid (all pids are in use)

void release pid(int pid) - Releases a pid

Create a number of threadsfor example, 100and each thread should request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period of time approximates the typical pid usage in which a pid is assigned to a new process, the process executes and then terminates, and the pid is released on the process's termination.) On UNIX and Linux systems, sleeping is accomplished through the sleep() function, which is passed an integer value representing the number of seconds to sleep.

The number of threads to create as well as the maximum sleep time will be passed on the command line as "program name" "number threads" "maximum sleep" (without the ") .

For example: ./a.out 100 15. This represents 100 threads, each with a random sleep time up to 15 seconds.

The solution should work for any number of threads, 100 is just an example.

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

Students also viewed these Databases questions

Question

=+how many times?

Answered: 1 week ago