fork编程实战(1)
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid;
int data;
while(1){
printf("please input a data\n");
scanf("%d",&data);
if(data == 1){
pid = fork();
if(pid > 0){
}else if(pid == 0){
while(1){
printf("do net requeat,pid = %d\n",getpid());
sleep(3);
}
}
}else{
printf("wait, do nothing\n");
}
}
return 0;
}
please input a data
3
wait, do nothing
please input a data
6
wait, do nothing
please input a data
1
please input a data
do net requeat,pid = 28747
do net requeat,pid = 28747
do net requeat,pid = 28747
do net requeat,pid = 28747