# Operating System #2 ## OS Services * 在這邊我們更詳細的列出OS提供的服務(尤其針對一般電腦)。 * 使用者介面 * Command-Line (CLI), Graphics User Interface (GUI), Batch * 程式執行 * 讓系統可以讀一個program到記憶體並執行、結束它(包含正常或不正常) * I/O * 提供使用I/O設備的接口 * 檔案管理 * 讀寫檔案,還有創造、刪除、搜尋、詳細資訊、權限設定等等 * 溝通 * 在同一台電腦可能Processes之間會互相交換資訊,或是透過網路在不同電腦之間傳遞,其封包或是記憶體共享等控制為OS的工作 * 錯誤偵測 * 可能發生在硬體或軟體方面 * 對於每個錯誤OS都應該找到合適的方法去解決 * 資源共享 * 分配使用者或程式應有的資源或空間 * 隨時追蹤使用者現在用了多少資源和是電腦中的哪種資源 * 對於資源進行保護和維持安全性也是OS的任務 ## System Calls * 一種程式介面,由OS所提供的。 * 通常使用高階語言撰寫(C或C++)。 * 但我們通常透過API(Application Program Interface)去使用system calls,而不是直接使用system call。 * 常見的API有Win32 API、POSIX API、Java API。 * 為什麼我們不直接使用system call,而要透過API呢? * 因為system call的功能通常太細,光是要複製檔案可能就要數十行才能達到。 * API就是幫我們把常見的功能包裝起來,更方便使用(不必知道system call的實作細節也能使用)。 * ![](https://i.imgur.com/yPv4zlj.png) ### Types of System Calls * 程序控制 * create process, terminate process * wait for time * Locks for managing access to shared data between processes * 檔案管理 * create file, delete file * open, close file * read, write, reposition * 裝置管理 * request device, release device * get device attributes, set device attributes * 資訊維護 * get time or date, set time or date * get system data, set system data * get and set process, file, or device attributes * 溝通 * create, delete communication connection * Shared-memory model create and gain access to memory regions * send, receive messages if message passing model to host name or process name * 保護 * Control access to resources * Get and set permissions * Allow and deny user access ###### tags: `note`