Re: [討論] 雙班系統程式期末考
雙班系程期末考,老師說會把下面題目列入考慮囉
以下是參考的解答
有錯的話大家就提出來吧
1. What is Zombie and Orphan?
1.Zombie: 若一個child process在parent process還沒有wait它之前就已經結束時,
我們稱此process為Zombie. Kernel會保留它的最少資訊,直到parent process執行wait
的動作.
2.Orphan: 若一個parent process在child process結束之前就已經結束,此時這個child
process被稱為Orphan. 它的parent process會被設成process "init"(PID 1),而init會
在這個child process結束的時候,會執行wait()來取得termination status.
延伸閱讀:講義的Why do we need Zombie?
(a)A parent can end up with two different children that share the same PID.
(b)A parent can end up trying to wait for the return code of another process'
child.
(c)The kernel won't be able to correctly track which return code goes with
which process.(unless it uses additional complex logic.)
2.Please draw the graph of the typical memory arrangement.
參考課本figure 7.6(有修改過)
3.Please describe the adavetage and disadvantage of shared library
and static library.
shared library
優點:
1.當library更新的時候方便更新,不必要重新compile或link
2.可以減少程式的檔案大小
缺點:
1.在程式loading或呼叫到shared library function的時候因為
需要dynamic linking,所以所花時間較多
2.程式執行的時候要確定系統裡有shared library
static library
優點:
1.比起shared library程式執行速度較快
2.不用要求系統內建library,library已經包含在程式中
缺點:
1.當library要更新時需要重新link或compile.
2.程式的檔案大小較大
When to use shared library?
1.library常常需要更新的時候
2.若使用shared library可清楚切割source code和GPL source code,可不用
follow GPL license.
3.減少程式的體積
When to use static library?
1.避免系統不存在shared library
2.自己寫的library.
3.加速讀取的時間
4.We know that we can register an exit handler by atexit(). But it seems that
we can't unregister an exit handler.Can we still have the effect that
just like we unregister some exit handler? How to do it?
1.yes
2.可以宣告一個global variable當作flag(例如 ex1_flag),然後在function的最開頭
先判斷,若ex1_flag=1時就往下執行,若ex1_flag=0時就不執行,這樣就算這個function
已經被註冊為exit handler,還是可以利用這個flag來選擇要不要被執行,有同樣的效果
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.30.84
※ 編輯: mycallmax 來自: 140.112.30.84 (06/15 20:23)
推
06/15 20:29, , 1F
06/15 20:29, 1F
推
06/15 20:33, , 2F
06/15 20:33, 2F
推
06/15 20:33, , 3F
06/15 20:33, 3F
→
06/15 20:33, , 4F
06/15 20:33, 4F
推
06/15 20:34, , 5F
06/15 20:34, 5F
推
06/15 20:36, , 6F
06/15 20:36, 6F
推
06/15 20:39, , 7F
06/15 20:39, 7F
推
06/15 20:47, , 8F
06/15 20:47, 8F
推
06/15 20:52, , 9F
06/15 20:52, 9F
推
06/15 20:56, , 10F
06/15 20:56, 10F
推
06/15 21:01, , 11F
06/15 21:01, 11F
推
06/15 21:24, , 12F
06/15 21:24, 12F
推
06/15 21:33, , 13F
06/15 21:33, 13F
推
06/15 21:49, , 14F
06/15 21:49, 14F
推
06/15 22:02, , 15F
06/15 22:02, 15F
推
06/15 22:05, , 16F
06/15 22:05, 16F
推
06/15 22:25, , 17F
06/15 22:25, 17F
推
06/15 22:40, , 18F
06/15 22:40, 18F
推
06/15 22:52, , 19F
06/15 22:52, 19F
推
06/15 23:01, , 20F
06/15 23:01, 20F
推
06/15 23:07, , 21F
06/15 23:07, 21F
推
06/15 23:17, , 22F
06/15 23:17, 22F
推
06/15 23:18, , 23F
06/15 23:18, 23F
推
06/15 23:29, , 24F
06/15 23:29, 24F
推
06/15 23:30, , 25F
06/15 23:30, 25F
推
06/15 23:42, , 26F
06/15 23:42, 26F
推
06/16 00:11, , 27F
06/16 00:11, 27F
推
06/16 00:34, , 28F
06/16 00:34, 28F
推
06/16 00:50, , 29F
06/16 00:50, 29F
推
06/16 01:22, , 30F
06/16 01:22, 30F
推
06/16 01:42, , 31F
06/16 01:42, 31F
推
06/16 08:40, , 32F
06/16 08:40, 32F
推
06/16 11:29, , 33F
06/16 11:29, 33F
※ 編輯: mycallmax 來自: 140.112.30.84 (06/16 15:45)
推
06/17 08:43, , 34F
06/17 08:43, 34F
討論串 (同標題文章)