1. Homepage
  2. Programming
  3. CIS3110 Operating Systems Assignment 1: Parallel computation using processes

CIS3110 Operating Systems Assignment 1: Parallel computation using processes

Engage in a Conversation
GuelphCIS3110Operating SystemsParallel computation using processesC

1. Description CourseNana.COM

CIS*3110 Assignment 1
Parallel computation using processes Due date: Friday, February 16, 11:59pm, Weight: 15%
CourseNana.COM

For this assignment you will write a parallel program that takes a list of file names as input and produces a new set of files, which contain the english alphabet histograms for each of the input files. CourseNana.COM

This assignment is individual work and is subject to the University Academic Misconduct Policy. See course outline for details. CourseNana.COM

Histograms are simply counts - in this case, counts of alphabet characters in the file. For example, given a file with contents
hello world
the characters a thorough d appear 0 times, e - 1 time, etc.. CourseNana.COM

Your program will consist of several processes - a parent and multiple children. These processes will communicate using pipes and signals. The structure of your program is described below.
CourseNana.COM

CourseNana.COM

Parent process CourseNana.COM

  • -  The parent process will accept multiple file names as command line arguments. The parent must be able to take any number of files as inputs. If no input files are provided through the command line, your program must display an error message and exit. CourseNana.COM

  • -  The parent program registers a signal handler for SIGCHLD CourseNana.COM

  • -  For every file, the parent will fork a child and pass the file name to it. How you do this is up CourseNana.COM

    to you - you can use a pipe, a variable that gets initialized by the parent and copied by the CourseNana.COM

    child, etc. Each child also gets a pipe for sending the data back to the parent. CourseNana.COM

  • -  The parent then goes in a loop and does nothing, avoid busy waits. Terminating children are CourseNana.COM

    dealt with by the SIGCHLD handler:
    - The process id of the terminated child is retrieved using waitpid(-1, CourseNana.COM

    &child_status, WNOHANG) - more on this later
    - The signal handler must display a message indicating it caught a SIGCHLD, and specify CourseNana.COM

    the child's PID.
    - The signal handler function checks how the child terminated: CourseNana.COM

    • -  If the child exited normally, the parent reads the character counts from that child's pipe, CourseNana.COM

      then closes the pipe's read end. The character counts are saved in the file called CourseNana.COM

      filePID.hist where PID is the process ID of the corresponding child. The format for CourseNana.COM

      the output file is stated below. CourseNana.COM

    • -  If the child terminated abnormally - either exited with a value other than 0, or was killed CourseNana.COM

      by a signal - the signal handler does not read the data, since there's nothing to read. 1 CourseNana.COM

  • -  The examples discussed in class and posted on the course website showed you how to get the exit status of a process. CourseNana.COM

  • -  The macros WIFSIGNALED and WTERMSIG will help you figure out if the child was killed by a signal (and which one), and the function strsignal will provide the name of the signal given its code. CourseNana.COM

    - Once the parent knows that all the children have terminated, it exits. CourseNana.COM

    In other words, the parent handles the terminating children and the data they send CourseNana.COM

    asynchronously. Instead of using a loop with wait, it catches every SIGCHLD generated by a terminating child process, checks the termination status, and reads the data from the children that terminated normally. CourseNana.COM

    It is possible that some children will terminate nearly simultaneously. This can be a problem - CourseNana.COM

    when multiple child processes terminate simultaneously and hence multiple SIGCHLDs are raised, the parent may get delivered only the first one of them and the others would be lost, since the kernel does not queue signals.
    CourseNana.COM

    It is somewhat unlikely in our case, since each child would be working on a file of different lengths. However, to avoid this problem, we will use a non-blocking version of waitpid with the WNOHANG flag. In addition, each process will sleep for a few seconds after it completes the task. These steps will prevent the race condition. CourseNana.COM

    Child processes CourseNana.COM

  • -  Once the child gets the file name, it opens it and computes the histogram.
    - If the file fails to open, the child closes the write end of the pipe and terminates with the CourseNana.COM

    return / exit value 1. CourseNana.COM

  • -  The calculated histogram is sent through a dedicated pipe to the parent as an array. Make CourseNana.COM

    sure you get the array size right, since you will be sending array of multi-byte values (e.g. CourseNana.COM

    ints). CourseNana.COM

  • -  The child goes to sleep for 10+3*i seconds, where i is the index of the spawned child, starting at 0. So the child process that was forked first would sleep for 10 seconds, second - 13 seconds, third - 16 seconds, etc.. CourseNana.COM

  • -  The child then closes the write end of the pipe and terminates with exit value 0. CourseNana.COM

    You will need to make the array of pipes global and keep track of what pipe corresponds to what child PID. This will give the signal handler access to the array of pipes and allow the signal handler figure out which pipe to read from depending on which child has terminated. How you do this is up to you. You will not be penalized for use of global variables - they are often used in low-level systems programming code out of necessity. CourseNana.COM

    Also, remember that any data allocated in the parent before you call fork will be dynamically allocated in the children - the children will "inherit" the already allocated data from the parent process. Such data must be freed in both the parent and the children. Use out to verify that CourseNana.COM

you are not leaking memory - see Lecture 4 for a note on how to use it with a multi-process program. CourseNana.COM

Histogram calculation CourseNana.COM

  • -  Read the file into an array of chars. You can also read it in one char at a time - it is up to you. CourseNana.COM

  • -  Go through every character in the array and calculate the number of occurrences of every CourseNana.COM

    letter. You can assume that the text is written using the 26-letter English alphabet. All other characters must be ignored. Upper- and lower-case forms of the same letter must be treated the same - e.g. 'A' counts as an occurrence of 'a'. CourseNana.COM

  • -  Be careful with the character array size - do not hardcode it! It must be determined and dynamically allocated at runtime. Remember to free all dynamically allocated data when you are done - both in the children and in the parent. CourseNana.COM

    Once the parent has received the histogram - which the child must send through a pipe as an array - the parent will save the histogram to a file using the following format (one letter count per line, each line has the letter and its corresponding count):
    a 12 CourseNana.COM

    b0 c 17 d3 ... CourseNana.COM

    Special inputs CourseNana.COM

    The command line arguments passed to the parent process are treated as file names - with one exception. If a command line argument is the string SIG, the corresponding child will not receive the filename - instead, the parent will send SIGINT to that child using the kill function. The child does not need to catch it - it should just terminate, using the default SIGINT disposition. CourseNana.COM

    For example, given the command: CourseNana.COM

    A1 file1.txt SIG file2.txt
    The child process 0 (the first fork) would be given file1.txt, child 1 would be sent SIGINT, and child 2 would be given file2.txt CourseNana.COM

    Using signal functions
 
 CourseNana.COM

    To use functions related to signals, we need to tell the C compiler to use the 2008-09 POSIX standard. You can put the statement #define _POSIX_C_SOURCE 200809L as the very first line in your code, above all other #include or #define statements. CourseNana.COM

    Alternatively, you can pass this macro value to your code through the compiler: CourseNana.COM

    gcc -D_POSIX_C_SOURCE=200809L file.c
    

You also need to include the relevant headers: unistd.h, signal.h, string.h, etc.. The first few lines of your code can look like this: CourseNana.COM

#define _POSIX_C_SOURCE 200809L
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

Compilation CourseNana.COM

Include a Makefile that compiles all your source code. The Makefile must compile your code with GCC, using the flags -Wall -g -std=c11. It must have the following targets:
- A1: the main executable fine implementing the assignment functionality
- clean: clean: the target that deletes the executable, as well as any other temporary files you CourseNana.COM

may have created when compiling the executable CourseNana.COM

You are welcome to use the makefiles provided in the code examples on the course website as a starting point. CourseNana.COM

Also, please include a README indicating known issues / bugs, as well as whatever additional instructions we may need to run your code. CourseNana.COM

2. Evaluation CourseNana.COM

Your code must compile, run, and have all of the required functionality implemented. It must compile and run with no errors on the CIS*3110 Docker image provided on the course website and discussed in class. CourseNana.COM

Any compiler errors will result in the automatic grade of zero for the assignment. Compiler warnings will result in mark deductions. CourseNana.COM

Your code will be tested with several text files. Marks will be deducted for:
- Incorrect and missing functionality, including a missing makefile
- Deviations from the assignment requirements
- File descriptions that you opened yourself and that are still open when your program CourseNana.COM

terminates - valgrind will be used for checking this
- Memory leaks and memory errors - these will also be checked for using valgrind CourseNana.COM

- Run-time errors, including infinite loops, crashes, race conditions, etc. - Failure to follow submission instructions CourseNana.COM

Your code will be compiled with the -Wall, -g, and -std=c11 flags. Make sure your code compiles with no errors and no warnings to avoid mark deductions. You can create a makefile for your code to speed up the compilation. If you do, the makefile must use the above flags.
CourseNana.COM

CourseNana.COM

3. Submission CourseNana.COM

Submit your source code and makefile as a Zip file using Moodle. The name of your file must me loginName.zip, where the loginName name is your standard UofG login. Make sure the archive a Zip format. As stated above, failure to follow these instructions will result in a mark deduction. CourseNana.COM

The assignment will be marked using the standard CIS*3110 Docker image provided on the course website and discussed in class. We will download and install a fresh image, create a container, and use Docker to run and grade your code. It will be compiled using the Makefile you have provided and we will execute the created file. Make sure you test your code accordingly. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Guelph代写,CIS3110代写,Operating Systems代写,Parallel computation using processes代写,C代写,Guelph代编,CIS3110代编,Operating Systems代编,Parallel computation using processes代编,C代编,Guelph代考,CIS3110代考,Operating Systems代考,Parallel computation using processes代考,C代考,Guelphhelp,CIS3110help,Operating Systemshelp,Parallel computation using processeshelp,Chelp,Guelph作业代写,CIS3110作业代写,Operating Systems作业代写,Parallel computation using processes作业代写,C作业代写,Guelph编程代写,CIS3110编程代写,Operating Systems编程代写,Parallel computation using processes编程代写,C编程代写,Guelphprogramming help,CIS3110programming help,Operating Systemsprogramming help,Parallel computation using processesprogramming help,Cprogramming help,Guelphassignment help,CIS3110assignment help,Operating Systemsassignment help,Parallel computation using processesassignment help,Cassignment help,Guelphsolution,CIS3110solution,Operating Systemssolution,Parallel computation using processessolution,Csolution,