操作系统代写|CISC324: Operating Systems Lab 1

这是一篇来自加拿大的操作系统代写

Toolbox

This lab has been prepared to be conducted on UNIX-like operating systems (e.g., Linux Ubuntu). Please make sure to have a well set up environment. You will need a computer, a Linux operating system (or MacOS, which is a UNIX based OS), and a C-compiler. You can still use the Windows operating system but you will have to install additional tools such as Cygwin. An alternative would be to install Linux on a virtual machine (e.g., VirtualBox or VMWare) over Windows. You can also remotely use the CASLAB Linux computers.

Background and Outcomes

During this lab, you will learn how to use the most important process management system calls. You will be writing programs, using C-programming language, to create new processes, terminate running processes, wait for processes (synchronization), change the code segment of processes, and get the attributes of processes. The following POSIX API system call primitives will be used:

To use these primitives, make sure that your C-program includes the following header fifiles: <unistd.h>, <wait.h>, <sys/types.h>, and <stdlib.h>.

1 Process Communication Issue

Assume that we possess a multiprocessing computer and that we would like to compute, using a computer program, the sum of a sequence from 0 to n (see equation below), where n > 0. To speed up the computations, we would like to implement our program in such a way so that we make use of multiprocessing.

A simple intuition consists of dividing the sum into two parts that will be run by two difffferent processes. Let us say process P1 executes the sum from 0 to [ n2 ], and process P2 executes the sum from [ n2 ] + 1 to n. Process P1 is set the task to display the fifinal result. Exer_1.c is a typical implementation of this scenario using the C-programming language under POSIX environment.

nXi=0 i = 0 + 1 + 2 + · · · + n

Explain how you fifixed the issue.

Note. You need to create a ReadMe.txt fifile to type down some of your answers.

2 Race-Condition Issue

The program in eXer_2.c consists of one parent process that creates three other child processes. Then, each child process, tries to execute the program count.c. By executing the latter program, each process opens a shared fifile named nums.txt, reads the stored value, increments it, then rewrites the new value back to the fifile, for 5000 times. By compiling the program count.c using commands such as ($cc count.c -o count.out) and placing the output in the same directory (folder) as program eXer_2.c, then if each of the three processes reads the value from the fifile nums.txt then increments that value before writing it back to the fifile, in the normal circumstances, we should fifind at the end of the execution that the fifile contains the value 15000 (5000×3).

What is the value of n (lower bound)? and provide an execution scenario that can lead to the fifinal value being n.

3 What to submit

4 What to check during submission