[理工] [OS] 99暨大資工
題目:
What are the possible output of the following program?
(Assume the new process is created successfully.)
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int value=101;
if(fork()<=0)
{
value += 22;
printf("The value is %d\n",value);
}
else
{
printf("The value is %d\n",value);
wait(NULL);
}
printf("Over with %d\n",value);
}
解:
(1)
The value is 123
Over with 123
The value is 101
Over with 101
(2)
The value is 123
The value is 101
Over with 123
Over with 101
(3)
The value is 101
The value is 123
Over with 123
Over with 101
問題: 想請問以上三個答案是怎麼來的?
感謝各位耐心看完題目及問題,謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.193.221.223
推
11/04 17:06, , 1F
11/04 17:06, 1F
→
11/04 17:06, , 2F
11/04 17:06, 2F
→
11/04 17:07, , 3F
11/04 17:07, 3F
→
11/04 17:08, , 4F
11/04 17:08, 4F
→
11/04 17:09, , 5F
11/04 17:09, 5F
→
11/04 17:09, , 6F
11/04 17:09, 6F
→
11/04 20:53, , 7F
11/04 20:53, 7F
→
11/04 20:54, , 8F
11/04 20:54, 8F
→
11/04 20:55, , 9F
11/04 20:55, 9F
推
11/04 21:07, , 10F
11/04 21:07, 10F
→
11/04 23:15, , 11F
11/04 23:15, 11F
推
11/17 22:34, , 12F
11/17 22:34, 12F