创建子进程,并打印父进程和子进程的ID

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

int main()
{
  pid_t pid;
  pid = fork();
  if(pid < 0)
  {
    printf("error in fork\n");
  }
    else if(0 == pid){
    printf("This is chile process, ID is %d\n", getpid());
  }
  else{
    printf("This is parent process, ID is %d\n", getpid());
  }

  return 0;
}

posted on 2012-11-03 15:19  青莲蓄池  阅读(2394)  评论(0编辑  收藏  举报

导航