Portfolio -- University Junior Year
A pid manager is a piece of software that is responsible for handling process identifiers. It is responsible for the following points:
- Creating and assigning process identifiers to new processes.
- Releasing the process identifier when that process completes execution.
- Reassigning this process identifier to a newly created process.
Each created process identifier should be unique, meaning that no two processes identifiers should have the identifiers. You are required to implement the following functions:
- int allocate map(void)—Creates and initializes a data structure for representing pids. This function returns -1 if unsuccessful, 1 if successful. You can use any data structure of your choice.
- int allocate pid(void)—Allocates and returns a pid. This function should return 1 if unable to allocate a pid (all pids are in use).
- void release pid(int pid)—Releases a pid.
One of the first IPC mechanisms in early UNIX systems were Pipes. Pipes acts as a conduit allowing two processes to communicate, they typically provide one of the simpler ways for processes to communicate with one another. Ordinary pipes are the most common type of pipes. Ordinary pipes allow two processes to communicate in standard producer– consumer fashion: the producer writes to one end of the pipe (the write-end) and the consumer reads from the other end (the read-end). As a result, ordinary pipes are unidirectional, allowing only one-way communication. If two-way communication is required, two pipes must be used, with each pipe sending data in a different direction. Design a program using ordinary pipes such that one process sends a string message to the second process. The second process should then reverse the case of each character in the message and sends it back to the first process. As an example, if the first process sends the message Hi There, the second process will return hI tHERE. This will require using two pipes, one for sending the original message from the first to the second process and the other for sending the modified message from the second to the first process.
Create a file-copying program named filecopy using ordinary pipes. This program should receive two parameters:
- The name of the file to be copied
- The name of the copied file
The program then must create an ordinary pipe and write the contents of the file required to be copied to the pipe. The child process should then read this file from the pipe and write it to the destination file. For example, if we invoke the program as follows:
filecopy file_to_be_copied.txt copy.txt
The file file_to_be_copied.txt will be written to the pipe. The child process will read the contents of this file and write it to the destination file copy.txt.
Create a multithreaded software that calculates may statistical parameters for a list of numbers. This program will receive a series of numbers on the command line and then creates a five separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value, the fourth will determine their median and the fifth will determine their standard deviation. As an example, suppose your program is passed the following series of integers:
80 72 11 25 59 82 99
The program should output:
- The average value is 61.14
- The minimum value is 11
- The maximum value is 99
- The median value is 72
- The standard deviation value is 29.68
Create a multithreaded program to calculate the value of π using MonteCarlo technique. This technique works as follows: Suppose you have a circle inscribed within a square, as shown in the below Figure:
Assume that the radius of this circle is 1. First, generate a series of random points as simple (x, y) coordinates. These points must fall within the Cartesian coordinates that bound the square. Of the total number of random points that are generated, some will occur within the circle. Next, estimate π by noticing that the area of the square is (2𝑟)² = 4𝑟² and the area of the circle is πr² , so this means that:
𝐴𝑟𝑒𝑎 𝑜𝑓 𝑐𝑖𝑟𝑐𝑙𝑒 / 𝐴𝑟𝑒𝑎 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒 = 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑝𝑜𝑖𝑛𝑡𝑠 𝑖𝑛 𝑐𝑖𝑟𝑐𝑙𝑒 / 𝑡𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑝𝑜𝑖𝑛𝑡𝑠 = πr² / 4𝑟²
Hence π can be estimated as:
π= 4× (number of points in circle) / (total number of points)
Hint: You need to create a separate thread that is responsible of generating a number of random points. The thread will count the number of points that occur within the circle and assign that result to a global variable. When this thread has finished, the parent thread will calculate and output the estimated value of π. What will happen when we increase the number of generated points? Justify your answer
Assume that for a certain system, it has a 32-bit virtual address with a 4-KB page size. Write a program that takes a virtual address (in decimal) on the command line and outputs the page number and offset for that given address. For example, if we input 19986 to the program, the output would be:
The address 19986 contains:
page number = 4
offset = 3602
You should use an appropriate data type to store 32 bits. Also, it will be a good idea to use unsigned data types as well.