C PROGRAMMING – PROCESS PARALLEL

Learning Goal: I’m working on a c programming question and need the explanation and answer to help me learn.

For this assignment you will extend countnames.c (from assignment #1) to compute the name counts of one or more input files in a parallel fashion using multiple processes. For example, the ith child process will process the ith file.

You will develop a program countnames_parallel that takes one or more input files on the command line. You will need to compute the count of names over all files similar to assignment #1.

Assume that you have several files with names separated by newlines. You want to read in and count the names from all the files. Same as in assignment #1 you can assume the files contain up to 100 different names with up to 30 characters in each.

If a file appears multiple times on the command line, those names will be processed multiple times.

You should use fork() to start a process for each of the files, such that we can compute a count for each file individually in parallel. To communicate between processes you may use pipe(). You need to wait for the processes to finish using wait().

You must be able to handle files with any number of names (including no names). You can assume that the files contain only valid ASCII characters separated by newlines (and possibly an occasional empty line, same as in assignment 1). A name can include spaces, for example “Tom Wu” is one name.

The code/ipc directory contains examples of using fork, pipe and wait, which you can consult for help.

For example, running on the names1.txt
Download names1.txt
and names2.txt
Download names2.txt
files will output:

$ ./countnames_parallel names1.txt names2.txt

which will output to stdout:

Tom Wu: 4
Jenn Xu: 2

In the example above, if an input file contained empty lines you should also print to stderr messages like (same as assignment 1, empty lines in a file don’t count and can be ignored for counting purposes):

Warning - file names1.txt line 3 is empty.

$ ./countnames_parallel names1.txt names2.txt names2.txt 

will output the following:

Tom Wu: 5
Jenn Xu: 4

Do you need help with this paper? 🏆 - Let us help you write it!

Why Choose Our Essay Writing Service?

  • ✅ Original writing: Our expert writers will write each paper from scratch, ensuring complete originality, zero plagiarism and AI free content.
  • ✅ Expert Writers: Our seasoned professionals are ready to deliver top-quality papers tailored to your needs.
  • ✅ Guaranteed Good Grades: Impress your professors with outstanding work.
  • ✅ Fast Turnaround: Need it urgently? We've got you covered!
  • ✅ 100% Confidentiality: Customer privacy is our number one priority. Your identity is anonymous to our writers.
🎓 Why wait? Let us help you succeed! Our Writers are waiting..

Get started

Starts at $9 /page

How our paper writing service works

It's very simple!

  • Fill out the order form

    Complete the order form by providing as much information as possible, and then click the submit button.

  • Choose writer

    Select your preferred writer for the project, or let us assign the best writer for you.

  • Add funds

    Allocate funds to your wallet. You can release these funds to the writer incrementally, after each section is completed and meets your expected quality.

  • Ready

    Download the finished work. Review the paper and request free edits if needed. Optionally, rate the writer and leave a review.