fork

#include <stdio.h>
#include <unistd.h>

int main()
{
int i = 10;
pid_t pid;
printf("Father's pid:%d\n", getpid());

pid = fork();
if(pid < 0)
{
perror("fork failure!");
return -1;
}
else if(pid == 0)
{
//while(1)
{
i++;
printf("Child's i = %d\n", i);
sleep(1);
}
}
else
{
printf("Child's pis:%d\n", pid);
//while(1)
{
printf("Father's i = %d\n", i);
sleep(1);
}
sleep(1);
}

return 0;
}
上一篇:实验六 进程基础


下一篇:实验六 进程基础