I am implementing the READERS WRITERS problem in C.
I need to spawn multiple readers. I did the following.
Code:
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
pid_t R1, R2, R3, W1, W2, W3;
R1 = fork();
R2 = fork();
R3 = fork();
if(R1 == 0 || R2 == 0 || R3 == 0)
{
printf("\nI am child ... \n");
return 0;
}
else
{
printf("\nI am parent ... \n");
return 0;
}
return EXIT_SUCCESS;
}
But I am getting weird output.
I need to print exactly 3 times "I am child ... "
and only 1 time "I am parent .. "