#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;
}
#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;
}