Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to get you comfortable with the use of processes and threads in the operating system of your choice. Select

The purpose of this assignment is to get you comfortable with the use of processes and threads in the operating system of your choice. Select either Windows or Unix/Linux (use Unix shell for Apple systems) and complete the following problems.

Problem 1: Write a program that accepts an integer N as a command line input and then proceeds to launch N processes on your system. Each process should consist of an infinite loop that prints out Process k running (once every second) where k is a process index (from 0 to N-1). After 5 seconds of running, your main program should kill process 0, then after another 5 seconds, should kill process 1, and so on until all processes have been terminated. At that time, your main program should itself terminate.

Hints: In Windows, you can use the function CreateProcess to launch a new process. My general approach to this problem is to create a separate source file for the launched mini-processes and compile it into an executable. Then, you can call that executable with CreateProcess. In Unix/Linux, this problem can be solved using the fork function. Using either OS, there is great online documentation (... Google it!...) for how to launch new processes from within a process.

Problem 2: Write a program that accepts an integer N as a command line input and then proceeds to launch N threads within that process. The remainder of the exercise is identical to Problem 1 except that you should print out Thread k running.

Hints: In Windows, you can use the function CreateThread to launch a new thread. In Unix/Linux, you can use the pthread library. There is great documentation online for both (thank you Google).

Problem 3: Discuss the similarities and differences between your solutions to Problem 1 and Problem 2. When might you want to use multiple processes for multi-tasking and when is it more appropriate to use multiple threads?

Your solution to these problems should be written in C or C++. I will accept solutions written for Windows or Unix/Linux. You should submit all of your source files (.c, .cpp, .h, etc.) as well as a text file or Word file with your answer to Problem 3.

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions