{"id":8524,"date":"2023-03-06T06:03:01","date_gmt":"2023-03-06T06:03:01","guid":{"rendered":"https:\/\/www.goodacademic.com\/blog\/questions\/c-programming-process-parallel\/"},"modified":"2023-03-06T06:03:01","modified_gmt":"2023-03-06T06:03:01","slug":"c-programming-process-parallel","status":"publish","type":"questions","link":"https:\/\/www.goodacademic.com\/blog\/questions\/c-programming-process-parallel\/","title":{"rendered":"C PROGRAMMING &#8211; PROCESS PARALLEL"},"content":{"rendered":"<div class=\"col-sm-12 messageContent\">\n <b>Learning Goal: <\/b>I&#8217;m working on a c programming question and need the explanation and answer to help me learn.<\/p>\n<p>For this assignment you will extend <strong>countnames.c<\/strong> (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.<\/p>\n<p>You will develop a program <strong>countnames<\/strong><strong>_parallel<\/strong> 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.<\/p>\n<p>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.<\/p>\n<p>If a file appears multiple times on the command line, those names will be processed multiple times.<\/p>\n<p>You should use <strong>fork()<\/strong> 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 <strong>pipe()<\/strong>. You need to wait for the processes to finish using <strong>wait()<\/strong>.<\/p>\n<p>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 &#8220;Tom Wu&#8221; is one name.<\/p>\n<p>The <a class=\"inline_disabled\" href=\"https:\/\/sjsu.instructure.com\/courses\/1560213\/files\/folder\/code\/ipc\" target=\"_blank\" rel=\"noopener\">code\/ipc<\/a> directory contains examples of using fork, pipe and wait, which you can consult for help.<\/p>\n<p>For example, running on the <code><strong><span class=\"ally-file-link-holder link_holder\"><span class=\"instructure_file_holder link_holder instructure_file_link_holder\"><a class=\"inline_disabled preview_in_overlay\" title=\"names1.txt\" href=\"https:\/\/sjsu.instructure.com\/courses\/1560213\/files\/71398947?wrap=1\" target=\"_blank\" data-canvas-previewable=\"false\" data-api-endpoint=\"https:\/\/sjsu.instructure.com\/api\/v1\/courses\/1560213\/files\/71398947\" data-api-returntype=\"File\" data-id=\"71398947\" rel=\"noopener\">names1.txt<\/a><a class=\"file_download_btn\" role=\"button\" download=\"\" href=\"https:\/\/sjsu.instructure.com\/courses\/1560213\/files\/71398947\/download?download_frd=1\" data-id=\"71398947\"><br \/>\n       <svg viewbox=\"\">\n        <path><\/path>\n       <\/svg> <span class=\"screenreader-only\">Download names1.txt<\/span><\/a><\/span><\/span><\/strong>and<strong> <span class=\"ally-file-link-holder link_holder\"><span class=\"instructure_file_holder link_holder instructure_file_link_holder\"><a class=\"inline_disabled preview_in_overlay\" title=\"names2.txt\" href=\"https:\/\/sjsu.instructure.com\/courses\/1560213\/files\/71398948?wrap=1\" target=\"_blank\" data-canvas-previewable=\"false\" data-api-endpoint=\"https:\/\/sjsu.instructure.com\/api\/v1\/courses\/1560213\/files\/71398948\" data-api-returntype=\"File\" data-id=\"71398948\" rel=\"noopener\">names2.txt<\/a><a class=\"file_download_btn\" role=\"button\" download=\"\" href=\"https:\/\/sjsu.instructure.com\/courses\/1560213\/files\/71398948\/download?download_frd=1\" data-id=\"71398948\"><br \/>\n       <svg viewbox=\"\">\n        <path><\/path>\n       <\/svg> <span class=\"screenreader-only\">Download names2.txt<\/span><\/a><\/span><\/span><\/strong><\/code>files will output:<\/p>\n<pre><code>$ <strong>.\/countnames_parallel names1.txt names2.txt<\/strong><\/code><\/pre>\n<p>which will output to <strong>stdout<\/strong>:<\/p>\n<pre>Tom Wu: 4<br>Jenn Xu: 2<br><br><\/pre>\n<p>In the example above, if an input file contained empty lines you should also print to <strong>stderr<\/strong> messages like (same as assignment 1, empty lines in a file don&#8217;t count and can be ignored for counting purposes):<\/p>\n<pre><code><strong>Warning - file names1.txt line 3 is empty.<\/strong><\/code><\/pre>\n<pre><\/pre>\n<pre><code>$ <strong>.\/countnames_parallel names1.txt names2.txt names2.txt <\/strong><\/code><\/pre>\n<p>will output the following:<\/p>\n<pre>Tom Wu: 5<br>Jenn Xu: 4<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learning Goal: I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":[],"disciplines":[733],"paper_types":[],"tagged":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/8524"}],"collection":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions"}],"about":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/types\/questions"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/comments?post=8524"}],"version-history":[{"count":0,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/8524\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/media?parent=8524"}],"wp:term":[{"taxonomy":"disciplines","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/disciplines?post=8524"},{"taxonomy":"paper_types","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/paper_types?post=8524"},{"taxonomy":"tagged","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/tagged?post=8524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}