[理工] [OS] fork()
#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
討論串 (同標題文章)
完整討論串 (本文為第 1 之 3 篇):