Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1.

The transition from user mode to kernel mode occurs when


 The application requests the help of operating System
 An interrupt
 A system call occurs.
The user cannot execute arbitrary code because entry into
the kernel is through controlled entry points.

2. The three I/O techniques are:

 Programmed I/O
 Interrupt Driven I/O
 Direct Memory Access(DMA)
While reading and writing large block of data it is
recommended to use Direct Memory Access(DMA).

3.Process switching is a type of context switching where we


switch one process with other process.It involves switching of
all the process resouces with those needed by a new process.

For context switch between two process p1 and p2 we should


save and restore memory addresses,page tables,kernel
resources, caches in the processor.
4. Thread Switching is a type context switching from one thread
to antoher thread in the same process.

The thread context switch needs to save the program counter


and registers.

Thread Switching is very efficient and much cheaper because it


involves switching out only identities and resources such as
program counter registers and stack pointers.

5. Yes its possible to have concurrency but not parallelism.

Concurrency:
Concurrency means where two different tasks or threads start
working together in an overlapped time period does not mean
they run at same instant.

Consider a scenario where Process ‘A’ and ‘B’ have four


different tasks P1,P2,P3andP4.so in order to go for execution ,
first process ‘A’of P1 executes , then Process ‘B” of P1
executes ,Secondly Process ‘A’ of P2 execution Process ‘B’ of P2
executes and goes on until all the threads are finished for their
execution.

Parallelism:
Parallelism is where two or more different tasks start their
execution at the same time.It means that the two tasks or
threads start working simultaneously.

Consider a scenario,When Process ‘A’ and ‘B’ and each have


four different tasks P1,P2,P3,P4 so both process go for
simultaneous execution and each works independently

Therefore , concurrency can be occurring number of times


which are same as parallelism if the process switching if the
process switching is quick and rapid. So,yes it is possible to
have Concurrency but not parallelism.

6.
Here balance is shared variable between two
processes.Race condition occurs when both processtry to use
the shared variable balance.

let us assume P1 is husband and P2 is wife

P1 reads balance 5000


P2 reads balance 5000

P1 withdraw 1000 balance = 4000


P2 deposit 1000 balance = 6000

which is inconsistent and this is called race condition


This issue can be solved in different ways

 Use write lock property in thread and monitor them


accordingly
 Don’t declare the amount as global variable.

7. Let us assume that


car is a process and bridge is a resource and busy waiting is
checking continuously if bridge is empty.

Only one process can use the resource at a time , we use binary
semaphore. so that only one process can use it. We add process
to an associated queue of processes that are waiting on that
semaphore allowing the semaphore to block the process and
then again wake it when semaphore is incremented. The
process should be added according to the timestamp of arrival.
We need a maximum allowed time for process to complete
after which resource is snatched otherwise it will process
forever.

8.Semaphores can be used to monitor and control the number


of concurrent open socket connection to communicate the
open connections existence and properties to other processes.
If the server knows about each open connection via this
semaphore communication,the server can then instruct each of
the individual processes to either quit making new connections
or to continue making new connections untill the limit is
reached.

9.

10. For the following code segments there are

 There are five Unique process are created


 There are two Unique methods are created

You might also like