C语言 fork
/* *@author cody *@date 2014-08-12 *@description */ /* #include <sys/types.h> #include <unistd.h> pid_t fork(void); */ #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> void Fork(){ pid_t pid; char *message; int n; pid = fork(); if(pid < 0){ perror("fork failed!"); exit(1); } if(pid == 0){ message = "this is the child\n"; n = 6; }else{ message = "this is the parent\n"; n = 3; } for(;n > 0;n --){ printf("%s",message); sleep(1); } } int main(int argc, char const *argv[]) { Fork(); return 0; }