Create threads causing a racing condition

Assignment Help Operating System
Reference no: EM131106424

Process ID (PID) manager in C for Linux

Instruction

In this project, you will implement a Process ID (PID) manager in C for Linux. An operating system's PID manager is responsible for managing process identi?ers. When a process is ?rst created, it is assigned a unique PID by a PID manager. The PID is returned to the PID manager when the process completes execution, and the manager may later reassign this PID. Process identi?ers are discussed more fully in Section 3.3.1. What is most important here is to recognize that process identi?ers must be unique; no two active processes can have the same PID. You can find the basic description of this programming project from Exercise 3.20 and 4.20. You need to further develop your solution ensuring that the data structure used to represent the availability of process identifiers is safe from race conditions. Use Pthreads mutex locks, described in Section 5.9.4 is a must. A start code is provided at the bottom of the page.

Step 1.

Implement the following APIs (functions) for obtaining and releasing a PID:

• int allocate_map(void)-Creates and initializes data structure for representing pids; returns -1 if unsuccessful, 1 if successful
• int allocate_PID(void)-Allocates and returns the largest PID available; returns -1 if unable to allocate a PID (all pids are in use)

You may use any data structure of your choice to represent the availability of process identi?ers. 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.

Step 2.

Writing a multithreaded program (at least 100 thread) that tests your PID manager implemented in Part 1. Ensure that the data structure used to represent the availability of process identi?ers is safe from race conditions using Pthreads mutex locks, described in Section 5.9.4. Write down the number of line where you use these methods in your PDF file,

pthread_mutex_init
pthread_mutex_lock
pthread_mutex_unlock

In your test program you will need to create 100 or more threads causing a racing condition. One racing condition example can be each thread constantly requests a PID in multiple iterations. Upon having a PID a thread sleeps for a random period of time, and then releases 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.) Output to the shell to reflect this random acquiring/releasing PID process. Finally, add this line to your output. Make a screenshot of your terminal window once your test program finishes.

printf("***DONE***\n");

Tips:

1.  Use the following constants to identify the range of possible PID values:

#define MIN PID 300
#define MAX PID 350

2.  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.

3.  Since you will use pthread library in Linux environment again you must include pthread.h and compile the source code with -lpthread option because GCC doesn't do auto-linking of libraries triggered by header inclusion. Here is an example,

gcc -lpthread -o testpid test.o pid.o

At the bottom of the start code there is Makefile which includes all commands you need to compile the 3 files.

Submission Instruction:

Combine all source code to a single .c file and should be named as yourCSUNID.c.

The PDF file comprising numbers of lines and your screenshots.

Attachment:- Attachments.rar

Reference no: EM131106424

Questions Cloud

How many shares of beck''s common stock were outstanding : Beck purchased 75,000 shares of its common stock and held it in Treasury. At December 31, 2011, how many shares of Beck's common stock were outstanding?
What are the principal considerations of a board of director : What are the principal considerations of a board of directors in making decisions involving dividend declarations? Discuss briefly.
Shortage cost and the one with a service level constraint : In both (R,Q) models, the one with a shortage cost and the one with a service level constraint, we set up Solver so that the multiple k is constrained to be nonnegative.
What was ambrose''s total debt : Ambrose plans to sell new common stock in the amount of $75,000. The firm's profit margin on sales is 6%; 60% of earnings will be retained. a. What was Ambrose's total debt in 2008? b. How much new long-term debt financing will be needed in 2009?
Create threads causing a racing condition : In your test program you will need to create 100 or more threads causing a racing condition. One racing condition example can be each thread constantly requests a PID in multiple iterations.
Develop organizational-level goals : Develop organizational-level goals. Develop departmental-contributor-level and individual-contributor-level goals aligned with the organizational goals.
What factors influence the dividend policy of a company : What factors influence the dividend policy of a company?
Assumption of customer responsibilities : How does the job of the CIO change with the assumption of customer responsibilities? Do you agree with this new development? Why or why not?
What will be the forecast for roberts'' year : Depreciation is expected to increase at the same rate as sales.Interest costs are expected to remain unchanged.The tax rate is expected to remain at 40%. On the basis of that information, what will be the forecast for Roberts' year-end net income?

Reviews

Write a Review

Operating System Questions & Answers

  Categorize the efficiency in terms

Consider the followimg nested loop contruct. Categorize the efficiency in terms of the variable n using "big-O" notation. Suppose the statements represented by the elipsis

  Steps and sub steps required to start an e business

Discuss the steps and sub steps required to start an e-business. Assume the Idea is already approved and the viability is already established through e-business plan.

  Creating virtual experiences

Think back over the past year. Where were you when you learned about breaking news? How did technology impact the way that you heard, saw, or experienced the newsworthy event?

  Execute the alias command and view the list of aliases

CIS 240 - Execute the alias command and view the list of aliases available to your user identity. Note that this list will vary from distribution to distribution and

  Purpose to apply the compensation knowledge in real-world

purpose to apply the compensation knowledge in real-world situation. the task formulating a compensation strategy for

  Identify various hardware components and network topologies

VaryNet Corporation wishes to create 4-individual offices across the globe. They wish to be able to connect these offices over the internet, and they want to make sure that each network is available to each other,

  What would be the monthly maintenance charges

Floor space in some unit other than ft sq -- such as the how many living rooms in your house would be required to hold the equipment, or football fields, or aircraft carrier decks, etc.

  Write program for unix that takes as input name of directory

Write a program for UNIX or Windows 7 that takes as input the name of a directory. The program should print a list of the files in the directory, one line per file, and after the file name, print the size of the file.

  Identify properties of communication channel

Write the send and receive primitives for stated processes. Identify at least three properties of communication channel or link in this scheme

  Intervlan routing

Submit a 1-page Word document containing a screenshot of your final score from each simulation as well as a 1-paragraph summary in your own words on your lessons learned. You will be graded based on your score for completing the simulations and th..

  What is the maximum memory address space

Consider a hypothetical microprocessor generating a 16-bit address (for example, assume that the program counter and the address registers are 16 bits wide) and having a 16-bit data bus.

  Shell to be able to execute the most recent command

shell to be able to execute the most recent command and also be able to execute a specified command from the history.  the printHistory function

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd