title: How to use fork() in c on a file
body: <p>I am trying to divide up a large file and <code>fork()</code> to read each part of the file. My program already reads in the file and counts the total number of word occurrences in the file using a doubly linked list. Now I need to divide the file up into different sections and use <code>fork()</code> on each. I have already used <code>mmap()</code>, but I am not certain on what to do with it, or on how to implement the <code>fork()</code> on this file. I have seen <code>fork()</code> examples, but none of them seem to do anything besides create a child process and print the pid numbers. Does anyone know of any good examples that would help for what I'm trying to do? Or how I could implement this part? </p>
  
  <p>Here is a part of my updated code:</p>
  
  <pre><code>             proc_num = atoi(argv[3]); // assign the PROCNUMBER to proc_num as an integer
               section = size/proc_num;
               // map file to memory and divide workload by passing different
               // starting address and stopping address to different processes
               if ((addr = mmap(0, size, PROT_READ, MAP_SHARED , file, 0)) == (void *) -1) {
                  perror("ERROR: Mapping did not work!");
                  exit(1);
               }
               char tmp_word[25];
               int  j, k = 0;
               addr = mmap(0, size, PROT_READ, MAP_SHARED , file, 0);
               char buf[proc_num][1024];
               // Create fork
               pid = fork();
               if (pid == -1) {
                  perror("ERROR: Fork failed!");
               } else {
                  for (i = 0; i &lt; proc_num; i++) {
                     for(j = 0; j &lt; size; j++) {
                        if(addr[i*size+j] != ' ' &amp;&amp; addr[i*size+j] != '\n') {
                           tmp_word[k]=addr[i*size+j];
                           k++;
                        } else {
                           tmp_word[k]='\0';
                           // Count the words
                           count_words(tmp_word, words);
                           tmp_word[0] = '\0';
                           k = 0;
                        }
                     }
                  }
               }
               kill(pid, SIGKILL);
               munmap(addr, size);
               close(file);
               } else {
                  perror("ERROR: Not a file!");
                  exit(1);
               }
  </code></pre>