看板 Grad-ProbAsk 關於我們 聯絡資訊
嗯...被101交大OS慘電所以來問問題了 1.A mutex lock is a special semaphore whose value ranges only between 0 and 1. (第1題) 這句是對的 但是我覺得不一定啊 counting semaphore應該不限定只能這兩個值吧 2.To flexibly utilize memory,the memories of user and kernel processes are all allocated through the general paging and virtual memory interface. (第4題) 直覺告訴我這是錯的 但確切不知道該怎麼改才好 3.When inserting our ATM card into an ATM machine,we will be requested to enter a 4-digit personal identification number for up to three times.If a person lost his ATM card,what is the chance that the thief can withdraw money from his account? (第10題) 答案是3/1000 不知道怎麼算出來的 4.Currently,the Unix kernel implements a method to avoid deadlock problems with kernel data structures from occuring in the kernel. (第11題) 想問這個錯在哪 5.The following program is vulnerable to buffer-overflow arrack: #include <stdio.h> int main(int argc,char *argv[]) { char buffer[256]; if(argc < 2) return -1; else{ strcpy(buffer,argv[1]); return 0; } } (第17題) 想問一下 是argv[1]給太長 buffer就會塞不下的關係嗎 拜託大家了~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.253.88.37 ※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1485942429.A.DD9.html
qwer123073: 突然發現code沒include <string.h> 02/01 17:50
qwer123073: 不過這題重點應該不是這個@@ 02/01 17:50
ken52011219: counting semaphore 跟 binary semaphore功能還是有 02/01 17:55
ken52011219: 差 至少counting semaphore 功能並非 mutex lock 02/01 17:55
ken52011219: kernel process 使用的是 slab 吧 02/01 17:56
ken52011219: 1-(999/1000 * 998/999 * 997/998) (? 我沒仔細算 02/01 17:59
yupog2003: 第三題答案應該是3/10000,最後是有送分 02/01 18:01
yupog2003: ㄟ不對,應該說更正為E 02/01 18:02
ken52011219: Unix 採用不處理 deadlock 02/01 18:03
yupog2003: 0000~9999共10000個數,我的算式是: 02/01 18:03
ken52011219: 它好像有個都錯的選項 02/01 18:03
yupog2003: (1/10000)+(9999/10000)*(1/9999)+(9999/10000)* 02/01 18:04
yupog2003: (9998/9999)*(1/9998)=3/10000 02/01 18:05
joeboy: 第一個一定要是binary semaphore 這是沒錯的,他都說是lo 02/01 18:05
joeboy: ck了 02/01 18:05
yupog2003: 嗯嗯對,有個都錯的選項,剛剛寄錯了 02/01 18:05
yupog2003: 2.kernel processes也許應該常駐在memory中的某一個區 02/01 18:07
yupog2003: 段,以增加效能?我猜的,我也不確定 02/01 18:07
joeboy: Strcpy如果你不回收的話他會多一個空間出來,變得不安全 02/01 18:09
joeboy: ,因為srtcpy 不會自動回收他,所以你要把它可用減1,確 02/01 18:09
joeboy: 保你剩下的資料不會被有心人士破壞 02/01 18:09
yupog2003: 4.印象中unix kernel是假裝沒deadlock這回事 02/01 18:10
joeboy: Kernel process這裡來說不會用到page跟VM吧?他可以直接 02/01 18:10
joeboy: 使用memory加快就不需要使用這兩個 02/01 18:10
kyuudonut: 樓上: 這跟回收沒有關係,原因是因為strcpy不會幫妳塞 02/01 20:17
kyuudonut: '\0',如果你直接用strcpy,結果後面忘記塞'\0', 02/01 20:18
kyuudonut: 會直接掛掉 02/01 20:18
joeboy: 謝謝糾正 02/01 20:59
k2shouai: 跟不塞/0沒關係,那頂多造成你之後印出奇怪東西而已。是 02/01 21:35
k2shouai: 你copy過來的字串大於你array大小時有可能會造成error, 02/01 21:35
k2shouai: 因為你會寫到不該寫入的地方。 02/01 21:35
kyuudonut: 若字串大於array大小,就不會有'\0'了 02/01 22:04
qwer123073: 我寫code用gcc編譯 執行出來是segmentation fault 02/01 22:05
qwer123073: 是寫到不該寫的地方無誤 02/01 22:05
kyuudonut: 因為沒有'\0',可能會無法停止而超出可以存取的位址 02/01 22:05
kyuudonut: @qwer 這是同樣的意思。 02/01 22:06
kyuudonut: 使用完strcpy,在buffer結尾塞'\0'是較安全的做法 02/01 22:07
kyuudonut: 你可以試試 02/01 22:07
kyuudonut: 阿,我知道我哪裡出問題了,感謝k2指正 m(_ _)m 02/01 22:34
qwer123073: 感謝各位解答 獲益良多 02/01 22:45