[理工] [OS] fork()

看板Grad-ProbAsk作者 (無法顯示)時間14年前 (2011/07/29 19:13), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
#include <stdio.h> #include <unistd.h> void func(int *input) { (*input)++; } int main() { pit_t pid; int k; k=3; pid = fork(); if(pid<0) { func(&k); printf("k=%d ", k); exit(-1); } else if(pid==0) { func(&k); printf("k=%d ", k); } else { wait(NULL); func(&k); printf("k=%d ", k); exit(0); } } (A) the output k of the parent process is 4 (B) the output k of the child process is 4 (C) the last output of k is 4 請問這段程式是怎麼跑的? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.166.118.200
文章代碼(AID): #1ECfNEod (Grad-ProbAsk)
文章代碼(AID): #1ECfNEod (Grad-ProbAsk)