Odd/Even Lines in given file - fork() child process
I've used fork() to create child processes for each command line argument. Within this, I want the child process to check if the argument is a valid filename/can read the file, if not it should return exist status -1. But if it can, it should count the lines in the file and return an exit status of 0 if even number or 1 if odd. I want the parent process to execute these child processes in parallel and use their exit status' to determine whether overall there is an even or odd number of lines in all of the files. Print odd or even to standard output and exit with 0 if even, 1 if odd.
Below is the code I've written so far to create the child processes. I was hoping someone could give me some idea as to how to get going on the childs and parents job sections. Any tips are appreciated.
Thanks!
Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int i;
pid_t pid;
for(i = 0; i < n; i ++)
{
pid = fork();
if(pid == 0) break;
}
if(pid == 0)
{
// Do child's job
}
else
{
// Do parent's job
}
}