Operating System Concepts CHAPTER 2 System Structures 1

  • Slides: 29
Download presentation
Operating System Concepts 作業系統原理 CHAPTER 2 系統結構 (System Structures) 1

Operating System Concepts 作業系統原理 CHAPTER 2 系統結構 (System Structures) 1

2. 1 n n n n n 作業系統服務(OS Services) 使用者介面(User interface (UI): Graphics User

2. 1 n n n n n 作業系統服務(OS Services) 使用者介面(User interface (UI): Graphics User Interface (GUI), Batch Interface, Command-Line (CLI) 程式執行(Program Execution) 輸入和輸出作業(I/O Operations) 檔案系統的使用 使用者及其他系統程式 通信(Communications) 錯誤偵測(Error Detection) Multiple Users 資源分配(Resource Allocation) 記帳(Accounting) 資源分配 保護和安全 3

Standard C Library Example n C program invoking printf() library call, which calls write()

Standard C Library Example n C program invoking printf() library call, which calls write() system call

Application Program Interface (API) n Mostly accessed by programs via a high-level n Application

Application Program Interface (API) n Mostly accessed by programs via a high-level n Application Program Interface (API) rather than direct system call use Three most common APIs are - Win 32 API for Windows - POSIX API for POSIX-based systems (Virtually all versions of UNIX, Linux, and Mac OS X) - Java API for the Java virtual machine (JVM) n Why use APIs rather than system calls? - Program Portability: the program can been compiler and run on any system.

Example of Standard API n Consider the Read. File() function in the Win 32

Example of Standard API n Consider the Read. File() function in the Win 32 API—a function for reading from a file n A description of the parameters passed to Read. File() q HANDLE file—the file to be read q LPVOID buffer—a buffer where the data will be read into and written from q DWORD bytes. To. Read—the number of bytes to be read into the buffer q LPDWORD bytes. Read—the number of bytes read during the last read q LPOVERLAPPED ovl—indicates if overlapped I/O is being used

System Call Parameter Passing n Three general methods used to pass parameters to the

System Call Parameter Passing n Three general methods used to pass parameters to the OS q Simplest: pass the parameters in registers n q Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register n q q In some cases, may be more parameters than registers This approach taken by Linux and Solaris Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system Block and stack methods do not limit the number or length of parameters being passed

11

11

2. 4 系統呼叫的類型 2. 4. 1 行程的控制(process control) n 正常結束、不正常中止執行(end, abort) n 載入、執行(load, execute)另一程式

2. 4 系統呼叫的類型 2. 4. 1 行程的控制(process control) n 正常結束、不正常中止執行(end, abort) n 載入、執行(load, execute)另一程式 n 建立行程、終止行程(create process, terminate process) n 獲取行程屬性、設定行程屬性(get process attributes,set process attributes) – 優先次序、最大容許執行時間 n 等待時間(wait for time) n 等待事件、顯示事件(wait event, signal event) n 配置及釋放記憶體空間(allocate and free memory) 12

MS-DOS execution (a) At system startup (b) running a program

MS-DOS execution (a) At system startup (b) running a program

Free. BSD Running Multiple Programs

Free. BSD Running Multiple Programs

2. 4. 2 檔案的管理(File management) n 建立檔案、刪除檔案(create file, delete file) n 開啟、關閉(open, close) n

2. 4. 2 檔案的管理(File management) n 建立檔案、刪除檔案(create file, delete file) n 開啟、關閉(open, close) n 讀出、寫入、重定位置(read, write, reposition) n 獲取檔案屬性、設定檔案屬性(get file attributes, set file attributes) – 檔案名稱、檔案類型等等 2. 4. 3 裝置的管理(Device management) n 要求裝置、釋回裝置(request device, release device) n 讀出、寫入、重定位置(read, write, reposition) n 獲取裝置屬性、設定裝置屬性(get device attributes, set device attributes) n 邏輯上加入或移去裝置(logically attach or detach devices) 15

2. 4. 4 資訊維護(Information maintenance) n 取得時間或日期、設定時間或日期(get time or date, set time or date)

2. 4. 4 資訊維護(Information maintenance) n 取得時間或日期、設定時間或日期(get time or date, set time or date) n 取得系統資料、設定系統資料(get system data, set system data) n 取得行程、檔案或裝置的屬性(get process, file, or device attributes) n 設定行程、檔案或裝置的屬性(set process,file,or device attributes) 2. 4. 5 通信(communication) n 建立、刪除通信連接(create, delete communication connection) n 傳送、接收訊息(send, receive messages) n 傳輸狀況訊息(transfer status information) n 連接或分離遠程裝置(attach or detach remote devices) 2. 4. 6 保護(protection) n 設定權限、取得權限(set permission, get permission) 16

Examples of Windows and Unix System Calls

Examples of Windows and Unix System Calls

2. 5 n 系統程式 (System Programs) System programs (System Tools) provide a convenient environment

2. 5 n 系統程式 (System Programs) System programs (System Tools) provide a convenient environment for program development and execution. The can be divided into: q q q q File manipulation (檔案的管理 ) Status information (狀態資訊) File modification (檔案的修改) Programming language support Program loading and execution Communications Application programs 使用者 應用程式 系統程式 作 業 系 統 硬 體