0% found this document useful (0 votes)
22 views

Computer operating system assignment 2

Uploaded by

jukes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Computer operating system assignment 2

Uploaded by

jukes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

No, I do not think a process can exist without any state.

A process is an instance of a program that is


being executed by the CPU¹. A process has a life cycle that consists of various stages, such as
creation, execution, termination, etc¹. Each stage corresponds to a state of the process, and the
process changes its state based on certain events or conditions². A process state transition diagram is
a graphical representation of how a process moves from one state to another during its life cycle³.
The following is an example of a process state transition diagram⁴:

![Process State Transition Diagram](^4^)

The diagram shows that a process can be in one of the five states: new, ready, running, waiting, or
terminated. The arrows indicate the possible transitions between the states. For example, a new
process becomes ready when it is loaded into the main memory, and a ready process becomes
running when it is selected by the CPU scheduler. A running process can become waiting if it requests
an I/O operation or waits for an event, or it can become ready if it is preempted by another process
or completes its time slice. A waiting process becomes ready when the I/O operation or event is
completed. A running process can also become terminated if it finishes its execution or encounters
an error.

Therefore, a process state transition diagram illustrates that a process always has a state during its
life cycle, and it cannot exist without any state. A stateless process would mean that the process has
no information about its current status or previous history, which is not possible for any program that
is being executed by the CPU. A stateless process would also imply that the operating system has no
way of managing or scheduling the process, which would affect the performance and functionality of
the system. Hence, a process cannot exist without any state.

Source: Conversation with Bing, 23/10/2023


(1) States of a Process in Operating Systems - GeeksforGeeks. https://www.geeksforgeeks.org/states-
of-a-process-in-operating-systems/.
(2) Process State Transition (Programming Interfaces Guide) - Oracle.
https://docs.oracle.com/cd/E19683-01/816-5042/psched-16/index.html.
(3) Process State Transition (Programming Interfaces Guide) - Oracle.
https://bing.com/search?q=process+state+transition+diagram.
(4) State Transition Testing – Diagram & Technique (Example) - Guru99.
https://www.guru99.com/state-transition-testing.html.
(5) State Transition Testing – Diagram & Technique (Example) - Guru99.
https://www.guru99.com/state-transition-testing.html.
(6) State Transition Diagram with example in software engineering. https://t4tutorials.com/what-is-
state-transition-diagram-software-engineering/.
(7) State-Transition Diagrams | StickyMinds. https://www.stickyminds.com/article/state-transition-
diagrams.
What is the difference between physical adress and virtual adress ? Explain the conversation of
virtual adress into physical adress by MMU(10) marks

A physical address and a virtual address are two different kinds of memory addresses used in
computing. A physical address refers to the actual location of a byte of data in the main memory,
such as a RAM chip. A virtual address is an abstraction that is used by the operating system and the
programs to access the memory without knowing the physical address. A virtual address is mapped
to a physical address by a hardware device called a memory management unit (MMU)¹².

The conversion of a virtual address into a physical address by the MMU is also known as address
translation. The MMU uses a data structure called a page table to store the mapping between virtual
and physical addresses. A page table consists of entries that indicate which virtual page (a fixed-size
block of memory) corresponds to which physical frame (a fixed-size block of memory in the main
memory). The MMU also uses a register called the page table base register (PTBR) to store the
physical address of the page table¹².

When a program accesses a virtual address, the MMU performs the following steps to translate it
into a physical address¹²:

- The MMU splits the virtual address into two parts: a page number and an offset. The page number
is used to index the page table, and the offset is used to locate the byte within the page.
- The MMU adds the value of the PTBR to the page number to get the physical address of the page
table entry (PTE) for that page.
- The MMU reads the PTE from the main memory and checks if it is valid. If it is not valid, it means
that the page is not present in the main memory, and a page fault occurs. The operating system then
has to load the page from the secondary storage (such as a disk) into an available frame in the main
memory, and update the PTE accordingly.
- If the PTE is valid, the MMU checks if it has the proper protection and access rights for that page. If
not, it means that the program is trying to access a forbidden or restricted page, and a protection
fault occurs. The operating system then has to handle this exception accordingly.
- If the PTE is valid and has the proper protection and access rights, the MMU extracts the frame
number from the PTE and concatenates it with the offset to get the physical address of the byte.
- The MMU accesses the byte from the main memory using the physical address.

This is how a virtual address is converted into a physical address by the MMU. I hope this helps you
understand this concept better.

Source: Conversation with Bing, 23/10/2023


(1) Difference between Virtual and Physical Address - javatpoint.
https://www.javatpoint.com/virtual-vs-physical-address.
(2) Virtual and Physical Addresses - University of Waterloo.
https://student.cs.uwaterloo.ca/~cs350/F14/notes/vm.pdf.
(3) Difference Between Virtual and Physical Addresses. https://www.tutorialspoint.com/difference-
between-virtual-and-physical-addresses.
(4) Physical address - Wikipedia. https://en.wikipedia.org/wiki/Physical_address.
(5) memory - Virtual vs Physical Address - Stack Overflow.
https://stackoverflow.com/questions/16484377/virtual-vs-physical-address.
(6) . https://bing.com/search?q=MMU.
(7) Manchester Metropolitan University - Homepage. https://www.mmu.ac.uk/.
(8) MyMMU | Manchester Metropolitan University. https://www.mmu.ac.uk/about-us/professional-
services/itd/software/learning/mymmu.
(9) Registry - Office Of Medical Marijuana Use. https://knowthefactsmmj.com/registry/.

Explain "race condition" and state how process synchronization is handled using semaphore? Explain
with algorithms.

A race condition is a situation where the outcome of a program depends on the relative timing or
order of execution of multiple threads or processes that share a common resource. A race condition
can lead to unexpected or incorrect results, such as data corruption, deadlock, or inconsistency. For
example, if two threads try to increment the same variable at the same time, they may both read the
same initial value, perform the increment operation, and write back the same incremented value,
resulting in a loss of one increment. ¹²³
Process synchronization is the technique of coordinating the actions of multiple threads or processes
that access a shared resource, such as a variable, a file, or a device. Process synchronization ensures
that concurrent threads or processes execute in a correct and predictable manner, and avoid race
conditions or other synchronization problems. ⁴⁵

One way to achieve process synchronization is by using semaphores. A semaphore is an integer


variable that represents the number of available units of a certain resource. A semaphore has two
atomic operations: wait and signal. The wait operation decrements the semaphore value if it is
positive (meaning there are available resources), or blocks the calling thread or process if it is zero or
negative (meaning there are no available resources). The signal operation increments the semaphore
value, indicating that a resource has been released, and wakes up a waiting thread or process if any.
⁴⁵

Semaphores can be used to implement mutual exclusion, which is the property that only one thread
or process can access a critical section (a section of code that accesses a shared resource) at a time.
To do this, we can use a binary semaphore (a semaphore that can only have values 0 or 1) as a lock.
The lock is initialized to 1, meaning it is available. Before entering the critical section, a thread or
process must acquire the lock by performing a wait operation on the semaphore. This will decrement
the semaphore value to 0, meaning it is locked. After exiting the critical section, the thread or
process must release the lock by performing a signal operation on the semaphore. This will
increment the semaphore value to 1, meaning it is available again. If another thread or process tries
to acquire the lock while it is already locked, it will be blocked until the lock is released.

The following pseudocode shows how semaphores can be used to implement mutual exclusion:

// Declare and initialize a binary semaphore


semaphore lock = 1;

// Thread or process A
wait(lock); // Acquire the lock
// Critical section
signal(lock); // Release the lock

// Thread or process B
wait(lock); // Acquire the lock
// Critical section
signal(lock); // Release the lock

Source: Conversation with Bing, 23/10/2023


(1) Race condition - Wikipedia. https://en.wikipedia.org/wiki/Race_condition.
(2) What Is a Race Condition? | Baeldung on Computer Science. https://www.baeldung.com/cs/race-
conditions.
(3) multithreading - What is a race condition? - Stack Overflow.
https://stackoverflow.com/questions/34510/what-is-a-race-condition.
(4) Semaphore (programming) - Wikipedia.
https://en.wikipedia.org/wiki/Semaphore_%28programming%29.
(5) What Is a Semaphore? | Baeldung on Computer Science.
https://www.baeldung.com/cs/semaphore.
(6) Semaphore - Wikipedia. https://en.wikipedia.org/wiki/Semaphore.
(7) Semaphore | Signaling, Telegraphy, Flags | Britannica.
https://www.britannica.com/technology/semaphore.

suppose three people are in line waiting for a department store to open for the big sale when the
door opens all three rush the door , but the door is not big enough for all them to pass through at
once . Describe a solution for adressing this deadlock that will allow three people to pass through the
door . which of the 4 necessary deadlock conditions does your solution break? Explain (15)
One possible solution for addressing this deadlock is to use a semaphore to control the access to the
door. A semaphore is an integer variable that represents the number of available units of a certain
resource. A semaphore has two atomic operations: wait and signal. The wait operation decrements
the semaphore value if it is positive (meaning there are available resources), or blocks the calling
thread or process if it is zero or negative (meaning there are no available resources). The signal
operation increments the semaphore value, indicating that a resource has been released, and wakes
up a waiting thread or process if any. ⁵

In this case, the resource is the door, and the processes are the people. We can initialize a binary
semaphore (a semaphore that can only have values 0 or 1) to 1, meaning the door is available.
Before entering the door, a person must perform a wait operation on the semaphore. This will
decrement the semaphore value to 0, meaning the door is occupied. After exiting the door, the
person must perform a signal operation on the semaphore. This will increment the semaphore value
to 1, meaning the door is available again. If another person tries to enter the door while it is already
occupied, they will be blocked until the door is released.

The following pseudocode shows how semaphores can be used to address this deadlock:

// Declare and initialize a binary semaphore


semaphore door = 1;

// Person A
wait(door); // Enter the door
// Shop inside
signal(door); // Exit the door

// Person B
wait(door); // Enter the door
// Shop inside
signal(door); // Exit the door

// Person C
wait(door); // Enter the door
// Shop inside
signal(door); // Exit the door

This solution breaks the circular wait condition for deadlock, which states that each process must be
waiting for a resource which is being held by another process, which in turn is waiting for the first
process to release the resource. In this case, there is no circular wait because each person waits for
only one resource (the door), and releases it after using it. Therefore, there is no cycle of waiting
processes.

Source: Conversation with Bing, 23/10/2023


(1) Conditions for Deadlock in Operating System - GeeksforGeeks.
https://www.geeksforgeeks.org/conditions-for-deadlock-in-operating-system/.
(2) Introduction of Deadlock in Operating System - GeeksforGeeks.
https://www.geeksforgeeks.org/introduction-of-deadlock-in-operating-system/.
(3) Deadlock - Wikipedia. https://en.wikipedia.org/wiki/Deadlock.
(4) Deadlock Definition & Meaning - Merriam-Webster. https://www.merriam-
webster.com/dictionary/deadlock.
(5) Dead bolt - Wikipedia. https://en.wikipedia.org/wiki/Dead_bolt.
(6) What is Deadlock and what are its four necessary conditions? - AfterAcademy.
https://afteracademy.com/blog/what-is-deadlock-and-what-are-its-four-necessary-conditions/.
(7) Deadlock in OS- Scaler Topics. https://www.scaler.com/topics/operating-system/deadlock-in-os/.
(8) 4 Conditions for Deadlock - University of Washington.
https://courses.cs.washington.edu/courses/cse451/98au/Lectures/9-deadlock/tsld003.htm.

You might also like