造梦西游吧吧 关注:145贴子:540
  • 0回复贴,共1
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <wait.h>
int main(){
pid_t pid;
pid = fork(); // Create the new process
setbuf(stdout,NULL); // Set unbuffered
char msg[] = "This is the race condition test\n"; // used to show the race condition
char* ptr;
int c;
// child process
if (pid == 0){
for(int i=0; i < 10;i++)
{
for(ptr = msg; (c = *ptr)!= 0; ptr++)
putc(c,stdout);
}
}
// parent process
else {
for(int i=0; i < 10;i++)
{
for(ptr = msg; (c = *ptr)!= 0; ptr++)
putc(c,stdout);
}
wait(NULL);
}
return 0;
}


IP属地:北京1楼2021-12-17 12:29回复