/*
*@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;
}

 

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2021-12-20
  • 2021-12-19
  • 2021-10-17
  • 2021-10-19
  • 2022-01-02
  • 2021-09-18
猜你喜欢
  • 2021-06-30
  • 2022-01-31
  • 2021-10-03
  • 2022-12-23
  • 2021-11-03
  • 2021-11-19
相关资源
相似解决方案