FL2440下的fork实验

来源:互联网 发布:mac恢复系统 编辑:程序博客网 时间:2024/06/02 21:08

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
main()
{
 pid_t pid;
 pid=fork();
 if(pid<0)
 {
  printf("fork error!/n");
  exit(1);
 }
 else if(pid==0)
 {
  while(1)
  {
           printf(" child process is running-----PID=%d/n",getpid());
    sleep(1);
  }
 }
 else
 {
  while(1)
  {
   printf("father process is running-----PID=%d/n",getpid());
   sleep(1);
  }
 }
 return 0;
}

原创粉丝点击