I have this problem to solve that I have no idea how to do it because there's only a few system calls we can use to solve it and I don't see how they are helpful for the situation.
The Exercise:
I have matrix with size [10][1000000] with integers and for each line I create a new process with fork(). The idea of each process is to go through all the numbers for that specific line and find a specific number then print a message about it. This was the first step of the problem and it's done. The second step is to print the total of occurrences of that number on each line by order. And in the end, the grand total of occurrences of that number.
The Calls:
The system calls I can use are described like this in the document for this exercise:
pid_t fork(void);
void exit(int status);
pid_t wait(int *status);
pid_t waitpid(pid_t pid, int *status, int options);
The Problem:
I have no idea how to do it because the exit()
call only allows me to pass a number below 256, what if the number of occurrences is larger than this number? How shall I return such a number?
Another Problem:
I don't exactly understand the difference between wait()
and waitpid()
and how/where to use one over the other. Besides the man pages, are there any more documentation where I can see code examples and such to understand them better? Or can someone explain me the differences and provide a basic example demonstrating such differences?