[OSC] Problem sheet 2
1.Using a simple system call as an example (e.g. getpid, or uptime), describe what is generally involved in providing the result, from the point of calling the function in the C library to the point where that function returns.
A system call is completed as follows:
mutual exclusion: only one process can be in its critical section at any one point in time
Progress: any process must be able to enter its critical section at some point in time
Fairness/bounded waiting: processes cannot be made to wait indefinitely
5.List and briefly explain the 4 conditions that must hold for deadlocks to occur (known as Coffman’s conditions). Give two examples of how you could undermine these conditions to prevent deadlocks from happening.
Example 2 : Allocate resources a number and force resource requests to be made in numerical order
6.List one advantage and one disadvantage for each of the following file systems:
i. Contiguous
ii. Linked list
iii. File allocation table
iv. I-nodes
Ex3 builds upon the Ex2 file system by adding:
A system call is completed as follows:
- As the function is called, an interrupt of the type “software exception” is placed on the processor, causing a Context Switch to take place between the calling function and the kernel.
- The exception handler will clear out and save user registers to the kernel stack so that control may be passed on to the C function corresponding to the syscall.
- The syscall is executed.
- The value(s) returned by the syscall is placed into the correctly corresponding registers of the CPU
- The handler takes this value, restores user registers and returns said value to the user program that called it.
- Timer interrupt is called.
- Trap into kernel space, switching to kernel stack
- Current applications’s registers are saved
- Scheduler gives next thread that should be run
- Context switch to other thread(load its stack, flush the TLB)
- Load user registers from the kernel stack
- PC register shifts to the beginning of the other application’s instruction
- When a context switch takes place, the system saves the state of the old process and loads the state of the new process
- switching process
1.Save process state(program counter, registers)
2.Update PCB(running->ready/blocked)
3.Move PCB to appropriate queue(ready/blocked)
4.Run scheduler, select new process
5.Update to running state in the new PCB
6.Update memory management unit(MMU)
7.Restore process
mutual exclusion: only one process can be in its critical section at any one point in time
Progress: any process must be able to enter its critical section at some point in time
Fairness/bounded waiting: processes cannot be made to wait indefinitely
5.List and briefly explain the 4 conditions that must hold for deadlocks to occur (known as Coffman’s conditions). Give two examples of how you could undermine these conditions to prevent deadlocks from happening.
- mutual exclusion: a resource can be assigned to at most one process at a time
- hold and wait: a resource can be held whilst requesting new resources
- No preemption: resources cannot be forcefully taken away from a process
- Circular wait: there is a circular chain of two or more processes, waiting for a resource held by the other processes
Example 2 : Allocate resources a number and force resource requests to be made in numerical order
6.List one advantage and one disadvantage for each of the following file systems:
i. Contiguous
ii. Linked list
iii. File allocation table
iv. I-nodes
- Contiguous
Pros: Simple to implement/optimal read/write performance
Cons: the exact size of file(process) is not always known beforehand/ Allocation algorithms needed to decide which free blocks to allocate to a given file/Deleting a file results in external fragmentation - Linked lists
Pros: Easy to maintain/file sizes can grow dynamically/no external fragmentation/Sequential access is straightforward
Cons: Random access is very slow/internal fragmentation/A block is no longer a power of 2/ Diminished reliability - FAT
Pros: Block size remains power of 2/Index table can be kept in memory allowing fast non-sequential/random access
Cons: The size of the file allocation table grows with the number of blocks, and might be too big - I-nodes
Pros: I-node is only loaded when the file is open
Cons:
Ex3 builds upon the Ex2 file system by adding:
- Tree based structures for directory files to facilitate indexing
- Journaling capabilities
评论
发表评论