1 / 10

Process management( 程序管理 )

Computer Science & Information Management. Process management( 程序管理 ). 程式與程序. 「執行一個程式或指令」就可以 『 觸發 』 事件而取得 PID 。. 程式與程序. 程式 (program) :通常為 binary program ,放置在儲存媒體中 ( 如硬碟、光碟、軟碟、磁帶等 ) 。

rosina
Télécharger la présentation

Process management( 程序管理 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science & Information Management Process management(程序管理)

  2. 程式與程序 • 「執行一個程式或指令」就可以『觸發』事件而取得PID。

  3. 程式與程序 • 程式 (program):通常為 binary program ,放置在儲存媒體中 (如硬碟、光碟、軟碟、磁帶等)。 • 程序 (process):程式被觸發後,執行者的權限與屬性、程式的程式碼與所需資料等都會被載入記憶體中, 作業系統並給予這個記憶體內的單元一個識別碼 (PID),可以說,程序就是一個正在運作中的程式。

  4. 查看process狀態 • 指令ps可查看process狀態 • ps –l可查看更進階的狀態內容。(如父程序)

  5. process專用函式

  6. 練習 • 撰寫p1.c程式,印出執行程式的pid以及父程序pid(ppid)。 #include<stdio.h> main(){ printf(“PID:%d, PPID: %d”, , ); } • 編譯:gccp1.c (-o 檔名) • 執行:a.out (執行檔檔名)

  7. 產生子程序(child process) • Unix啟動時剛開始只有一個程序(init),其pid為1。 • 使用fork指令可以產生子程序 Parent, init (PID 1) Child 1 (PID=4) Child 2 (PID=5) Child 3 (PID=6)

  8. 產生子程序(child process) • fork • 重製一份程序(process) • 當fork執行成功 • 回傳子程序(child)的PID給父程序(parent)。 • 回傳數值0給子程序(child)。

  9. 練習 • 撰寫p2.c程式並在程式中fork出子程序。 • 利用if判斷該程序為parent 或 child,並印出其pid。 #include<stdio.h> main(){ printf(“PID: %d”, getpid()); int child = fork(); if(…) }

  10. process排程 • 若有兩個以上的程序(parent, child)在執行,且皆會使用大量的電腦資源(CPU運算、IO)。則電腦會按照作業系統的排程法則來運作。 • 試撰寫大量迴圈運算,並利用父子程序搶奪資源,查看執行狀態。

More Related