Hi, I need to write a program that alternates between parent and child, which the child printing first. I need to output Parent or Child, the pid, and a random Number. It compiles fine, but nothing outputs. Any help?
Thank you
int main(int argc, char *argv[])
{
// Declarations
int randomNumC, randomNumP;
int numOfRandomNumbers = atoi(argv[1]);
char childWritesToPipe[1], childReadsFromPipe[1];
char parentReadsFromPipe[1], parentWritesToPipe[1];
int pipe1[2];
int pipe2[2];
char character = 'T';
int index, count;
pipe(pipe1); // Creating my pipe
pipe(pipe2);
int pid = fork(); // Creating child process
srand(numOfRandomNumbers); // Getting seed
// For loop that will go through numOfRandomNumbers < 20
for(int i = 0; i < numOfRandomNumbers; i++)
{
if(pid < 0) // if pid is less then zero, there was an error
exit(1);
if(pid == 0)
{
srand(randomNumC); // Getting a different seed for Child Random Numbers
randomNumC = rand(); // Generating random number