title: Two processes handling their own lines of code in one main function (c++)
body: <p>So my task goes like this:</p>
  <p>The program needs 2 processes <strong>in one main function</strong></p>
  <ul>
  <li>First process creates or opens a file &quot;log.txt&quot; which is in the same directory where the program is located. Then it adds user input to this file.</li>
  <li>Second process is a &quot;monitor&quot; of this file. It checks if the file exists, shows its size and shows how many characters were entered since the second process started.</li>
  </ul>
  <p><strong>Note</strong> that I am aware that the program itself is a process, but it needs to be done like that. There are some &quot;tips&quot; to use a file as mutex (CreateFile parameters) that would be the dsShareMode with FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE parameter.</p>
  <p>Now my question is: how do you create 2 processes to handle its own line of code? I've seen many examples of <code>CreateProcess</code> function but I don't really understand the first two parameters of this function</p>
  <ul>
  <li>lpApplicationName
  and</li>
  <li>lpCommandLine</li>
  </ul>
  <p>What am I supposed to pass to it in order to run 2 processes, one to handle the user input and the other to be the &quot;monitor&quot;?</p>
  <p>The first process is meant to handle those lines of code:</p>
  <pre><code>        std::string buffer;
          std::cout &lt;&lt; &quot;Enter your text:&quot; &lt;&lt; std::endl;
          getline(std::cin, buffer);
          HANDLE hFile = CreateFile(&quot;log.txt&quot;, FILE_APPEND_DATA, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
          DWORD written = 0;
          WriteFile(hFile, buffer.c_str(), buffer.size(), &amp;written, NULL);
  </code></pre>
  <p>While the second process should only care about this:</p>
  <pre><code>hFile = CreateFile(&quot;log.txt&quot;, FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
          if (hFile == INVALID_HANDLE_VALUE)
          {
              std::cout &lt;&lt; &quot;CreateFile error &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;
          }
          else
          {
              DWORD size = GetFileSize(hFile, NULL);
              std::cout &lt;&lt; &quot;\nCurrent file size: &quot; &lt;&lt; size &lt;&lt; std::endl;
              CloseHandle(hFile);
          }
  
          int stringLength = 0;
          for(int i=0; buffer[i]; i++)
              stringLength++;
  
              std::cout &lt;&lt; &quot;\nCharacters given since last startup: &quot; &lt;&lt; stringLength &lt;&lt; std::endl;
  </code></pre>