Skip to content

Used multiple parallel processes to compute histogram from multiple input files using POSIX.

Notifications You must be signed in to change notification settings

carterrows/POSIX-processes

Repository files navigation

README for Assignment 1 - Carter Rows (1170615)

State of implementation

Everything is working as expected. The program allows any number of file inputs, and also correctly deals with the SIG option in the cmd line.

Pipe functionality

To implement the pipes in this assignment, I declared two int** arrays for the child to parent and parent to child communication.

These arrays are global variables which are dynamically allocated in main() to be the same size as the number of cmd arguments, minus the ".exe" argument.

Each child PID corresponds to a specific int* array in the int** array, and this is calculated using the modulus operator. For example, if we have 10 children, and a child PID 372, that child would get the pipe index of 372 % 10 which is 2. Using the modulus to find pipe indexes for each child makes it so that the signal handler and parent process can know the correct pipe index corresponding to any child PID.

Memory management

Since the pipe arrays are dynamically allocated before forking each child, I deallocated the arrays in both parent and all child processes before exitting. To make sure there are no memory leaks in the case of an unexpected exit of a child, a child SIGINT handler takes care of deallocating memory before the child terminates with exit(1).

I have tested every possible scenario with valgrind using --trace-children=yes --leak-check=full -s and have found no memory leaks, so I hope you cannot find any.

Another note on the child's SIGINT handler

I decided to write a SIGINT handler for the children in order to prevent memory leaks. I hope this is not seen as deviating from the assignment guidelines, because the outline says to use the default SIGING response of terminating. But without a SIGINT handler, the pipe array would not be deallocated in the child process, leading to a memory leak. After terminating the child in my SIGINT handler, the parent still gets a SIGCHLD to deal with the terminating child.

Obviously if I were to use the default handler, I could just remove my signal handler for SIGINT, and the child would simply terminate and still be caught by the parents SIGCHLD handler. However, testing with this method, I got memory errors while using valgrind.

About

Used multiple parallel processes to compute histogram from multiple input files using POSIX.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published