C语言 fork

时间:2023-11-09 21:12:02
/*
*@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 < ){
perror("fork failed!");
exit();
}
if(pid == ){
message = "this is the child\n";
n = ;
}else{
message = "this is the parent\n";
n = ;
}
for(;n > ;n --){
printf("%s",message);
sleep();
}
} int main(int argc, char const *argv[])
{
Fork(); return ;
}