---
# System prepended metadata

title: 作業系統複習

---

# 作業系統複習
## Review
1. What is the purpose of **system calls**: 
The purpose of system calls serves as the interface between an operating system and a process.

2. When we use the **“fork()”** system call to create a new child process, how do we know which process is the parent process and which process is the child process?
If a call to fork() returns 0 it means that it is the child process that called the fork(). While if the return value of fork() is a positive integer, it means that the fork() was executed in the parent process and the returned positive integer is a PID of the child process.

3. Briefly explain how does **Linux** operating system support the idea of **“thread”**
In Linux, threads are implemented as a lightweight alternative to processes, and they are known as "lightweight processes" or "LWP". They share the same memory space as the parent process and scheduled by the kernel, which means they can communicate with each other more easily and efficiently.
Linux threads are implemented by the clone() system call, which creates a new task with has a copy of the attributes of the current process. The child (clone) task shares with the parent (cloned) task: virtual memory.

4. Briefly explain the issue of **“priority inversion”** in job scheduling 
Priority inversion is a situation that can occur when a low-priority task is holding a resource such as a semaphore for which a higher-priority task is waiting. 两者的优先级因此倒转。

6. What does the **“taskset”** command do in Linux?
The taskset command is used to set or retrieve the CPU affinity of a running process given its pid, or to launch a new command with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system.

7. Neccessary Conditions for **Deadlock**：
**Mutual Exclusion:** 某些資源在同一個時間點最多只能被一個 process 使用
**Hold and wait:** 某 process 持有部分資源，並等待其他 process 正在持有的資源
**No preemption:** process 不可以任意強奪其他 process 所持有的資源
**Circular Wait:** A set of processes are waiting for each other in a circular fashion. For example, lets say there are a set of processes {P0,P1,P2,P3} such that P0 depends on P1, P1 depends on P2, P2 depends on P3 and P3 depends on P0. This creates a circular relation between all these processes and they have to wait forever to be executed.

7. When a system is in a safe state, there will no deadlock in the system. Briefly explain **when a system can be in a safe state:**
A state is safe if the system can allocate resources to each process( up to its maximum requirement) in some order and still avoid a deadlock. Formally, a system is in a safe state only, if there exists a safe sequence. So a safe state is not a deadlocked state and conversely a deadlocked state is an unsafe state.

15. Briefly explain the **“worst fit”** solution in finding memory space for a program
The memory manager places a process in the largest block of unallocated memory available. The idea is that this placement will create the largest hold after the allocations, thus increasing the possibility that, compared to best fit, another process can use the remaining space.

17. **When should the contents of the translation look-aside buffer (TLB) be flushed away (cleaned up)?** You need to explain the reasons.
every time there is a change in address space, such as a context switch, the entire TLB has to be flushed. Because some TLB entries can become invalid, since the virtual-to-physical mapping is different.

19. Briefly explain how the concept of **“demand paging”.**
Demand paging is a memory management technique that allows programs to access memory only when it is needed. When a program requests a page that is not currently in memory, the demand paging system will bring that page into memory from secondary storage, such as a hard disk.

21. Briefly explain the **main problem** of the **“optimal page replacement” algorithm.**
All OS can not use this. This algorithm is difficult to implement because the operating system can't predict the future reference strings.
1. Briefly explain how the **SCAN disk scheduling algorithm** works.
read and write head has to move in one direction and fulfill all the requests until we move to the end of the disk. 然后调转方向。
3. Briefly explain **why using the DMA could help the system performance.**
allowing external devices to transfer information directly to or from the PC's memory without using the CPU.

8. Unix/Linux system: **permission “731”** ![](https://i.imgur.com/kNHhaQP.png)


10. Briefly explain the **bit vector managing free disk space** we covered in the class.
It contains the number of bits where each bit represents each block. If the block is empty then the bit is 1 otherwise it is 0. Initially all the blocks are empty therefore each bit in the bit map vector contains 1.

10. Briefly explain what the **Linux command “dd”** is used for
Linux command “dd”: Data duplicator. 可以無視操作系統的情況下一塊一塊的將數據從原始地址複製到目的地

1. Briefly explain the purpose of using **“procfs” in Linux.**
The /proc file system (procfs) is a special file system in the linux kernel. It's a virtual file system: it is not associated with a block device but exists only in memory.

15. A **race condition** is an undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time, but because of the nature of the device or system, the operations must be done in the proper sequence to be done correctly.

17. 英文課本作者：Abraham Silberschatz, Peter B. Galvin, Greg Gagne
18. 中文課本作者：武內覺


