Memory is allocated for a given process when a user starts a program. The OS can give each process a different amount of memory based on the amount requested when the process is created.

computer science

Description

Solutions to each of the 2 problems (2 separate programs) should be submitted via D2L. All solutions are to be written in C.

Memory is allocated for a given process when a user starts a program. The OS can give each process a different amount of memory based on the amount requested when the process is created. So, requests to the OS are received from applications to allocate (creation) or to free (termination) memory. The OS services the request and gives the new process the memory requested according to 3 popular algorithms:


 First fit: Satisfy the request from the first available free memory block that is large enough to accommodate the request. 

• Best fit: Satisfy the request from the free memory block that is large enough to service the request and small enough that it has the smallest fragmented block. 

• Worst fit: Satisfy the request from the free memory block that is large enough to service the request and creates the largest fragmented block.


N indicates the process (1) that is being created needs memory (500 bytes). The result of this operation is either successful (indicated by a memory address returned that references the new memory) or a failure (indicated by a NULL memory address returned). The T operation is terminating the process (process 7 in this case) and freeing the memory that was assigned to the process. The S operation is to stop the program and print the report.


You are to write a program (no pthreads! – YAY) that will simulate the memory allocations/frees of the operating system. Your program will read input from stdin and produce output on stdout. Each line will be one of the three forms above.


Related Questions in computer science category