看板 Grad-ProbAsk 關於我們 聯絡資訊
首先 first 先print fork出一個process如下 ╭────╮ │ main() │ ╰─┬──╯ ╭┴─╮ │ 子 │ ╰──╯ 此時會有兩個process在裡面 所以second會print兩次 因為parent process裡面有wait的動作代表他會等待child執行完畢 因此會print fourthfifth 再來換父process print thirdfifth Done 有錯請指證! ※ 引述《wsx02 ()》之銘言: : After executing the program shown below, what is the output on the screen? : main() : { : int status, pid; : printf("first\n"); : pid = fork(); : printf("second\n"); : if(pid != 0) : { : wait(&status); : printf("third\n"); : } : else : { : printf("fourth\n"); : } : printf("fifth\n"); : } : 答案是 : first : second : second : fourth : fifth : thrid : fifth : 請問是怎麼跑出來的? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.169.104.4
wsx02:謝謝 03/13 21:21