CSC2404 Assignment 1: Operating Systems, System Calls, and Concurrency

Verified

Added on  2022/10/01

|14
|2232
|35
Homework Assignment
AI Summary
This document presents a comprehensive solution to CSC2404 Assignment 1, focusing on core operating system concepts. The assignment delves into system calls, explaining their necessity, the mechanisms behind them, and their role in interacting with the kernel. It explores cache management, including its purpose, importance, and the challenges of maintaining cache coherency in single and multi-processor systems. The solution then differentiates between concurrency and parallelism, analyzing the advantages and disadvantages of kernel and user threads, and examining the behavior of multithreaded code. Finally, the assignment addresses interrupts and traps, clarifying their purposes, differences, and significance in modern computer systems, along with the role and importance of timers. The solution references relevant resources like man pages and provides detailed explanations and examples to illustrate these concepts.
Document Page
1
csc2404 Assignment 1
Semester 2, 2019
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2
Document Page
3
Question 1 (marks 25)
system call” is used by a process to request that the kernel perform a task on behalf of the requesting
Why is it necessary that the kernel perform tasks on behalf of processes? Why doesn’t the process
perform the task itself? (6marks)
It is necessary for the kernel to perform because it is considered as the heart of the operating
system. It is used to provide an interface between the software and the data that is being processed
by the hardware components. The kernel also is used in providing the lowest abstraction method
for the available resources which application control so that different functions are accomplished.
The kernel makes this possible through interprocess communication appliance (Helmke
Hudson and Hudson, 2013 ).
The process cannot perform this task by themselves due to the following reasons.
The process cannot provide an interface between the applications and hardware components.
Another reason is that processes do not have the interprocess communication mechanism thus they
cannot communicate with each other and enable the communication between the applications
and hardware components.
Document Page
4
The details of the system call interface is hidden from the programmer as the operating system
supplies a library of standardised function calls4. Linux and macOS has over 300 such system
functions.
Explain how these functions actually notify the kernel that a service is being requested of
it, and (4 marks
Answers:
In registering, a system call is an automatic manner by which a PC program demands an
administration from the bit of the working system it is executed on. A framework called is a
for projects to cooperate with the working framework. A PC program makes a system call when it
makes a solicitation to the working system bit. System call gives the administrations of the
working framework to the client programs through. Application Program Interface(API). It gives
an interface between a procedure and a working framework to permit client level procedures to
demand administrations of the working framework. Framework calls are the main section focuses
on the piece framework. All projects requiring assets must utilize framework calls.
Explain the different methods used to: 3MKS
fork() it creates the processes.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
5
exit() it exits the processes
wait() it waits for a single object.
identify the system call being requested, and 3 mks
cat /usr/include/asm/unistd.h | less
pass the data to the kernel that may be required by the system call (3 marks).
Call gate this is a unique location put away by the bit in a rundown in part memory
at an area known
to the processor. At the point when the processor distinguishes a call to that
address, it rather diverts
to the objective area without causing an entrance infringement
Which of the systems described here does Linux use? (2 mks)
Answers
Linus system use kernel thread
Using actual Linux system calls as examples, explain what sort of tasks an operating system will
perform on behalf of a process? (see the man pages intro(2), syscalls(2), and Section 2).
Answers :
The operating system accomplishes the following tasks.
It provides security to the processes i.e protects the process from unauthorized access.
It monitors overall process health until all the processes are accomplished.
It detects any error in the process before they are completed.
It manages memory when the processes are being executed.
It manages the files on the computer.
It is also used in the process scheduling and allocates specific time to them to prevent a
collision.
Document Page
6
Document Page
7
Question 2 (marks 25)
Caches are an integral part of modern processor design. What is a Cache? What is its purpose?
(5Mks)
A cache is a collection or a group of items that are normally stored in a hidden area or
a place which is not accessible.it can also be defined as a memory type that is used to rise the
speed of information access in the computer processes.
Its main purpose is that it increases the speed of data access.it also stores data so that it can be
used frequently during processing.
What is cache management. Why is it an important design problem? (4 mks)
Cache management is the process by which data is organized and stored into software and
hardware so that it can be used in the future. It involves storing data into catche so that it can
be easily accessed in different processes.
Cache management is an important design problem because it involves storing data that is
stored elsewhere in the computer memory so that it can be accessed at high speed from the
computer.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
8
What is cache coherency (4 mks)?
This is the consistency and uniformity of data that is shared and end up being stored in multiple
and different local cache areas. This happens because when the client maintains data within the
same cache area problems may arise with incoherent data which is mostly the case with the
multiprocessing operating systems. It manages conflict between different data storage areas.
Discuss, with examples, how the problem of maintaining the coherency of cached data manifest itself in
the following pro- cessing environments: (6mks)
a. Single-processor systems,
In a computing domain where just one procedure executes at once, this game plan represents no
challenges, since access to whole number A will consistently be to the duplicate at the
the largest amount of progression. Be that as it may, in performing multiple tasks condition,
where the CPU is exchanged forward and backward among different procedures, extraordinary
consideration must be taken to guarantee that, on the off chance that few procedures wish to get
to An, at that point each procedure will get the most as of late refreshed worth of A
b. Multi-processor systems.
It is a bit more complicated since each of the CPUs might
contain its own local cache. In such an environment, a
copy of A may exist simultaneously in several caches.
Document Page
9
Question 3 (marks 25)
a. Explain the difference between concurrency and parallelism.
Concurrency is when two or more tasks can, start, run and complete in the same corresponding
time periods, This does not actually mean that the two tasks will be running instantly e.g
multitaskingon a single-core machine while parallelism is is when tasks actually kept running
simultaneously, it only exists of two different threads are being executed instantaneously e.g on
a multicore processor
b. There are two ways to support threads: kernel threads or user threads
(1) Most operating systems support both ways. Explain the advantages and disadvantages of
kernel
threads and user threads, (6 mks).
Advantages
Kernel thread are normally good for applications that are blocked frequently.
The scheduler gives the application that has more threads more time because the kernel
thread has more knowledge on all the threads.
User threads can be applied on OS that does not support threads.
They are fast to be managed.
They are fast and efficient this is because threads are simpler to be managed than the
procedure calls.
Disadvantages
The threads are slower and not efficient.
Document Page
1
0
It is more complex than the normal thread.
The user threads luck coordination between the kernel and the operating system.
They require the non-blocking calls or else they will more slow than usual.
(ii) Linux and Windows maps one user thread to one kernel thread. What are the advantages and
disadvantages of this method over other methods (4mks)?
Advantages
Kernel thread are normally good for applications that are blocked frequently.
The scheduler gives the application that has more threads more time because the kernel
thread has more knowledge on all the threads.
User threads can be applied on OS that does not support threads.
Disadvantages
The user threads luck coordination between the kernel and the operating system.
Consider the following code:
#include <stdio.h> #include <unistd.h> #include <pthread.h>
void *runAsThread(void *param); int main() {
int i;
pthread_t tid; pid_t pid;
for(i=0; i<3; i++) { pid = fork();
pthread_create(&tid,NULL,runAsThread,NULL); pthread_join(tid,NULL);
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
1
}
}
(i) Explain what is happening within the for-loop. Your explanation must include the
purpose and the effect of the three system calls (6mks).
When the for loop is being executed, the following processes are taking palace
New processes are created in the loop using the fork() function.
A new thread is started in the for a loop by the method pthread_create().
It waits for a thread to terminate using the method pthread_join()
(ii) Including the initial parent process, how many processes are created. (Do not supply a number
only, explain how you came to your answer) ( 3 mks)
3 processes are created since the loop runs thrice.
(iii) How many unique threads are created? (Do not supply a number only, explain how you
came to your answer) ( 3 mks)
3 threads are created in the network
Document Page
1
2
Question 4 (marks 25)
a. What Is the purpose of interrupts? Why are they a critical concept of modern
computers?
The purpose of the interrupt is to move a program to a specific address so that it can be used
used for some specific events.it also transfer the mode switch to kernel mode.
Interrupts are special signals that are sent to a computer CPU from the external components
like I/O devices. Their main purpose is that they tell the CPU to stop the current processes
and perform the important part of the operating system which is being executed at the current
time.
There are following are types of interrupts with their functions.
Trap- This is a software-generated interrupt that is used to signal the completion of an I/O
device so that the OS can obviate for device pulling.
b. How does a trap differ from an interrupt? (6 mks)
A trap differs from an interrupt in the following ways.
A trap this is an execution that occurs in users process. It is normally caused when zero divides or
when the memory access process is invalid (Mauerer, 2010 ). It is also used in summoning the system
call because it runs with high status than the handlers code. In most cases, the code anticipates the
trap to happen because it depends on it. Its handling is synchronous this means that its code can be
held and continues after some time.
While an interrupt this is anything that can be generated by hardware components this include I/O
devices of a computer. It is asynchronous, unlike the trap. The interrupt handler always waits for
them to happen before they are executed.
chevron_up_icon
1 out of 14
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]