操作系統系統調用
系統調用簡介 (Introduction to System calls)
The interface between the operating system and the user program is defined by the set of extended instruction that the operating system provides. These extended instructions are known as system calls. User program communicates with the operating system and request services from if by making system calls. There exist a library procedure corresponding to each system call that the user program can call. System call allows user-level processes to required services of the operating system. This procedure put the parameter of the system call in a specified place, such as the machine registers, and then issue TRAP instructions to start the operating system. When the operating system gets control after TRAP it examines the parameters to see if they are valid and if so perform the work requested. When it is finished the operating system puts a status code in a register telling whether it succeed or failed and execute a RETURN FROM TRAP instructions to return control back to the library procedure. The library procedure then returns to the caller in the usual way, returning the status code as a function value.
操作系統和用戶程序之間的接口由操作系統提供的一組擴展指令定義。 這些擴展指令稱為系統調用 。 用戶程序與操作系統進行通信,并通過進行系統調用來請求服務。 存在與用戶程序可以調用的每個系統調用相對應的庫過程。 系統調用允許用戶級進程訪問操作系統所需的服務。 此過程將系統調用的參數放在指定的位置(例如,機器寄存器),然后發出TRAP指令以啟動操作系統。 當操作系統在TRAP之后獲得控制權時,它將檢查參數以查看它們是否有效,并執行所需的工作。 完成后,操作系統將狀態碼放入寄存器中以告知其成功還是失敗,然后執行RETURN FROM TRAP指令將控制權返回給庫過程。 然后,庫過程以通常的方式返回到調用者,將狀態碼作為函數值返回。
Any operation perform in the system require the system and if any error occurs in the system it needs additional system calls for solving the errors. Suppose if any program wants to open a file and the file of that name may not exist in the system, in this case, the program print a message on the console window that the file does not exists all these things done by the system calls. System calls are callable from the assembly language. We have often encountered phrase such as “ assembly language under DOS”. We should now be clear about its meaning. The assembly language programmer needs to know the assembly language instructions set for that machine. In addition, he normally needs to aware of the system calls of the operating system running on that machine. Many high-level languages such as C and also enables the system calls to be embedded explicitly in the midst of other statements. Some high-level language such as JAVA or C++ does not need the explicit use of system calls embedded in other statements. In these scenarios the compiler substitutes system calls at specific locations.
系統中執行的任何操作都需要系統,并且如果系統中發生任何錯誤,則需要其他系統調用來解決錯誤。 假設有任何程序要打開文件,而系統中可能不存在該名稱的文件,在這種情況下,該程序會在控制臺窗口上打印一條消息,指出該文件不存在系統調用完成的所有操作。 可以從匯編語言調用系統調用 。 我們經常遇到諸如“ DOS下的匯編語言”之類的短語。 現在,我們應該清楚其含義。 匯編語言程序員需要知道該機器的匯編語言指令集。 另外,他通常需要知道該計算機上運行的操作系統的系統調用 。 許多高級語言(例如C)還使系統調用可以顯式地嵌入到其他語句中。 某些高級語言,例如JAVA或C ++,不需要顯式使用嵌入在其他語句中的系統調用 。 在這些情況下,編譯器將在特定位置替換系統調用 。
The two-parameter will be substituting various sets of operations system calls for the same source's statements such a fread, fwrite or execute. Generally, the mapping between the system calls of two operating system is never straightforward. Normally before the real system calls, the compiler produces machine instructions which are preparatory instructions for that system call.
這兩個參數將用操作系統調用的各種集合替換同一源的語句,例如fread,fwrite或execute。 通常,兩個操作系統的系統調用之間的映射從來都不是簡單的。 通常,在實際系統調用之前,編譯器會生成機器指令,它們是該系統調用的準備指令。
系統調用的類型 (Types of system calls)
System calls can be grouped into five categories- process control, file management, device management, information management, and communication.
系統調用可以分為五類: 過程控制 , 文件管理 , 設備管理 , 信息管理和通信 。
1.過程控制 (1. Process control)
A process or the job which is currently run in the system always want to load and execute another program. The command interpreter executes a program for example when the user clicks on the mouse button. Now the question arises that when the loaded program terminates when the control return. When any new program terminates in the system the memory the currently running program must be saved. So in this way we can efficiently create a program which calls another program and both are running concurrently. For the multiprogramming, we have created jobs or process. So the system calls for this purpose is called create a process or submit the job. When a new job, process or the group of the process is created then we have to manage the execution of these process.
當前在系統中運行的進程或作業總是要加載并執行另一個程序。 例如,當用戶單擊鼠標按鈕時,命令解釋器將執行程序。 現在出現的問題是,當加載的程序在控件返回時終止。 當任何新程序在系統中終止時,必須保存當前正在運行的程序。 因此,通過這種方式,我們可以有效地創建一個程序,該程序調用另一個程序,并且兩個程序同時運行。 對于多程序,我們創建了作業或過程。 因此,為此目的而進行的系統調用稱為創建流程或提交作業。 創建新作業,流程或流程組時,我們必須管理這些流程的執行。
2.文件管理 (2. File management)
In the file management system, we should be able to create or delete the files. For creating a file the system call requires the names of the file and some attribute of the files. When the file is created we should be able to open and use these files. We can also read-write or reposition the files. After all the work is done we need to close the file which indicates that the file is no longer need. We can also use these operations for directories also. In the file management system, we should be able to determine the values of various attributes for the file and directories. There are various file attributes like name, types, size, location, accounting information and so on. The two important system calls get attribute and file set attribute is required for this function.
在文件管理系統中,我們應該能夠創建或刪除文件。 為了創建文件,系統調用需要文件名和文件的某些屬性。 創建文件后,我們應該能夠打開和使用這些文件。 我們還可以讀寫文件或重新放置文件。 完成所有工作后,我們需要關閉文件,這表明不再需要該文件。 我們也可以將這些操作用于目錄。 在文件管理系統中,我們應該能夠確定文件和目錄的各種屬性的值。 有各種文件屬性,例如名稱,類型,大小,位置,記帳信息等。 此功能需要兩個重要的系統調用get屬性和file set屬性。
3.設備管理 (3. Device management)
When the program is running in the system it needs some resources such as memory, input, output, and so on. The resources are only granted when they are available and not held by another process. If the resources are not free the program has to wait for the resources. Files are the abstract or virtual devices. So there are many system calls which are needed for the files and also for the devices. If there are multiple users then first it requests for the devices and after finishing the work with these devices we should release it. When the devices are allocated to the user then we can perform different operations like reading, write and execute.
當程序在系統中運行時,它需要一些資源,例如內存,輸入,輸出等。 僅當資源可用且不由另一個進程持有時才授予資源。 如果沒有釋放資源,則程序必須等待資源。 文件是抽象或虛擬設備。 因此,文件和設備都需要許多系統調用。 如果有多個用戶,則首先請求設備,完成這些設備的工作后,我們應該釋放它。 將設備分配給用戶后,我們可以執行不同的操作,例如讀取,寫入和執行。
4.信息管理 (4. Information management)
In information management, various system calls are used to communicate the information between the operating system and user program. For example, some system has a system call forget the current time or date. There are many another system call like for the number of the user, different versions of operating system., free space in memory etc.
在信息管理中,各種系統調用用于在操作系統和用戶程序之間傳遞信息。 例如,某些系統有一個系統調用會忘記當前時間或日期。 還有許多其他系統調用,例如用戶數量,操作系統的不同版本,內存中的可用空間等。
5.溝通 (5. Communication)
There are mainly two models for communication. First is the message passing model in this the information is exchanged between the process and this communication facility is provided by the operating system. When the process wants to communicate first the other communicator should be know so that the communication is established and they can communicate. Second is the shared memory model in this model different process shared memory and communicate with each other.
主要有兩種通信模型。 首先是消息傳遞模型,其中信息在進程之間交換,并且該通信工具由操作系統提供。 當該過程首先要進行通信時,應該知道其他通信者,以便建立通信并可以進行通信。 其次是共享內存模型,在此模型中不同進程共享內存并相互通信。
翻譯自: https://www.includehelp.com/operating-systems/system-calls-in-operating-system.aspx
操作系統系統調用