“fork() can be thought of as a ticket to power. Power can sometimes be thought of as a ticket to destruction. Therefore, you should be careful while messing with fork() on your system, especially while people are cranking their nearly-late semester projects and are ready to nuke the first organism that brings the system to a halt. It’s not that you should never play with fork(), you just have to be cautious. It’s kind of like sword-swallowing; if you’re careful, you won’t disembowel yourself.” – Brian Hall
In this project multiprocessing & multithreading C programs are created to process multiple data sets. These programs calculate the mean and the median value for each data set and print out results for all data sets. Data sets are stored in files that consists of integer numbers separated by whitespace. The programs are able to process any number of data sets that are passed through from the command line and perform calculations concurrently using multiple processes and multiple threads.
For each data set, the program creates a child process. Each child process first reads all data from the file, perform the calculations, and sends the statistics back to the main process via a Unix pipes. Finally, the program prints out the results in a tabular format.
The program creates a thread to process each data set. Each thread perform operations for its data set and passes them to the parent thread. The program then waits for all threads to finish and print out all results in a tabular format.