fork()

来源:互联网 发布:淘宝客助手软件那个好 编辑:程序博客网 时间:2024/06/08 09:43
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>int main(int argc, char *argv[]){  pid_t pid;  printf("Process creation study. \n");  pid=fork();  switch(pid){  case 0:    printf("child process is running, pid=%d, getpid()=%d, getppid()=%d. \n", pid, getpid(), getppid());    break;  case -1:    perror("process craeteion failed \n");    break;  default:    printf("parent process is running, pid=%d, getpid()=%d, getppid()=%d. \n", pid, getpid(), getppid());    break;  }  sleep(10000);  exit(0);}


0 0