assign1_COSC 4302 Fall 2023 Answers

docx

School

Lamar University *

*We aren’t endorsed by this school

Course

COSC-430

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by AgentRiver13517

Report
COSC 4302: Introduction to Operating Systems Homework 1 Due: 10:00am, Sept. 5, 2023 (Tuesday) Name: _Md Shafaqul Islam Hamim_ LUID: _L20593148_ Date: _09/05/2023_
(20 points) 1. We discussed the following example solution in our class. Is it possible to have three simultaneous processes in execution? Please give one example to support your answer. It is possible to have three simultaneous process in execution. The Operating system uses multiprogramming, multithreading and multiprocessing to execute multiple processes at the same time. The example below is a problem that has three independent processes executing concurrently. L0: count = 2;       <compute A1>;       update (x);       FORK (L3);      <compute B1>; L1: JOIN (count);        retrieve (y);        goto L0; L2: <compute B2>;       QUIT(); L3: retrieve (x);        <compute A2>;        update (y);        FORK(L2);        goto L1;
Therefore, from the code and the step by step execution diagram we can see there can be three concurant processes running. (20 points) 2. Write a C or C++ program on Linux/Unix that creates a child process that prints a greeting, sleeps for 20 seconds, then exits. The parent process should print a greeting before creating the child, and another after the child has terminated. It should then terminate. Answer: The answer to this question is added as a .c file. The file name is greetings.c. (15 points) 3. What is the difference among algorithms, programs, and processes? Answer: Differences are listed below between algoritms, programs, and processes. Algorithm Program Process It is a step by step procedure for solving any problem. It is a set of instruction that tells a computer what operations to purform. It is an instance of a running program. It has a high abstraction. Medium abstruction. Low abstruction Its lifespan is permanent. A program lifespan is until the program is terminated Its lifespan is until the process is terminated. It has natural language or speudocode. It is coded in programming language. It is in binary language. (15 points) 4. What is the difference between a classic process and a thread? Answer: A classic process and a thred are both independent sequences in a computer in execution. They have many differences: Process: 1. Process is a program in execution. 2. It has own memory space, data, code and other resources. 3. Processes are heavier than threads. 4. It is created and managed by the OS. 5. Context switching between processes are relatively expensive. Thread: 1. Thread is a lightweight process and belongs to a process. 2. It shares the memory space, code and other resources with the process where it originates from. 3. Threads can be created or managed by the programmer or the OS. 4. Context switching is cheap. 5. Threads are usually lighter than process. (30 points) 5. Please work on the following programming question:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The program first creates a child process CP. So, there are two processes: The parent process does the following: a. compute the sum of all the even numbers from 1, 2, .. 1000, and output this sum; b. wait for the termination of the child process CP, then terminate; The child process does the following: a. compute the sum of all the odd numbers from 1, 2, .. 1000, and output this sum; b. terminates; Answer: The code is attached as a .c file. The file name is Assignment1Q5.c Note: 1. Please type all your homework. 2. Please program on Unix/Linux platforms. You may use either C or C++. How to Turn In: Softcopy: Please use BlackBoard to turn in your homework solutions. For programming questions, please do NOT use MS WORD. Please send .c files. Class Policy: Some programming questions are used in previous semesters. Please do NOT borrow solutions from those students who have taken this class before. We keep a database of all previous solutions. Programming solutions will be checked carefully for plagiarism. Students who are caught copying directly will receive 0 for this assignment.