1. How does a System call works?
System call is an interface to access privileged resources from user-level process. User-level process calls system call which executes in safe and secure privileged(kernel) mode and avoid any misuse of resources which might have global impact.
System call is set of assembly level instruction or set of function call from c library which access operating system resources and can be executed by kernel only. Whenever a user level process wish to access these resources, it calls the system call function. This system call function internally calls an interrupt 0X80 which transfer execution from user code to kernel code. Each system call is identified by a number which has to be declared in one file and is generally wrapped around _sys_call function.
2. What kind of information is stored in process control block?
A process control block contains process state in a structure. It contains process id, list of open file descriptor associated, memory info, process state, pointers to other data structure etc. It contains all the required information to start the process at later point of time and plays a crucial role in context switch.
3. Which scheduling algorithm is best in terms of avg waiting time? Why is it not used in real life situation?
I guess shortest process next is the best algorithm but this may lead to starvation of long job in real life situation hence it is not used.
4. What is semaphore and what operations can be performed on it?
Semaphore is a variable used for synchronization of various resources among many processes such that race condition can be avoided. Only read and write operation are possible on semaphore and it can be either binary or a counting type of variable. Semaphores are a special kind of locks.
5. Describe one approach for avoiding dead lock while using locks for synchronization between multiple processes?
One approach is to forcefully take back the locks after a given time.
Second approach is to not provide locks to more than certain number of resources.
Third approach is to use deadlock avoidance approaches while giving locks.
6. "LRU page replacement" algorithm?
This is least recently used page replacement algorithm.As the size of memory is fixed and number of pages that can be kept in the memory are limited hence there must be some rule to decide which page should be replaced to make way for incoming page. LRU is replacement of page which is not used for longest period of time.
7. What is thrashing and why it occurs?
Thrashing is a situation when excessive page replacement happens which leads to more time and resources wasted in paging rather than actual system progress.
8. Why most OS's maintain file buffer in main memory? What is the benefit?
Most OS maintain the file buffer in main memory because doing disk IO for each read or write operation will be too costly and resource intensive. This is reduce the system speed and hence increase latency.
9. What is an inode and what kind of information does it contain?
Inode is file system data structure which contains basic file metadata. it contains information on group id, device id, length, file mode and reference count etc. This information can be retrieved by stat command.
10. What is the difference between soft and hard link in a file system?
Hard link refers to same file Inode while soft link refers to different file Inode.
Part II
1. P1 10 unit
2. P2 1 unit
3. P3 2 unit
4. P4 1 unit
5. P5 5 unit
Assuming all process arrive at time O.
With FCFS
Process name turnaround time waiting time
P1 10 0
P2 11 10
P3 13 11
P4 14 13
P5 18 14
With RoundRobin
Process name turnaround time waiting time
P1 18 8
P2 2 1
P3 5 7
P4 4 3
P5 14 9
Part III
Sleeping barber problem:
See what are the resources.
Customer is resource for barber.
Barber is resource for customer.
free seats is resource for customer.
Barber:
While(true){
// occupy a customer
P(customer)
P(accessseats)
numberofaccessseat++;
V(barber)
V(accessseat)
}
Customer:
P(access seat)
if (numberofaccessseat > 0){
}
Try doing this at your own.
Part IV
Current disk head position: 49
moving towards track: 100
pending I/O request: 42 78 3 51 99
SSTF:
51 42 78 99 3
total track seeked: |49 - 51| + |51 - 42| + |42 - 78| + |78 - 99| + |99 - 3| = 164 units
SCAN:
51 78 99 3 42
Total track seeked: |49 - 51| + |51 - 78| + |78 - 99| + |99 -100| + |100| + |0 - 3| + |3 - 42| = 182 units
Using SSTF more frequently used data should be stored in the middle so that distance from any corner or position on the disk will be mediocre and pending track request will be served faster.
No comments:
Post a Comment