title: handling a job with spawn (start, termination) with socket-io Nodejs
body: <p>I have two questions here:</p>
  <ol>
  <li><p>is there any way to manage child_proccess (spawn) which running with nodejs?</p>
  </li>
  <li><p>suppose I have a script that starts do some functionality, I need to start the execution with socket.io event. I need to stop this execution with another socket io event.</p>
  </li>
  </ol>
  <p>the first idea that came through my mind was :</p>
  <p>start execution command with <strong>spawn</strong> and store the PID of the job in Redis. in the stop event, get PID from Redis and kill that process with another spawn with below command:</p>
  <pre><code>kill = spawn(`kill ${PID}`)
  </code></pre>
  <p>but os kernel does not allow nodejs to kill that process unless nodejs runs with <strong>sudo</strong> command.I am the owner of that <strong>child_procces</strong>. why I can't stop that?</p>
  <p>the second Idea is to use global variable :</p>
  <pre><code>io = ()=&gt;{
  let job = null;
  socket.on(&quot;start&quot;, ()=&gt;{
      job = spawn(&quot;path/to/my/script&quot;)
  })
  socket.on(&quot;stop&quot;, ()=&gt;{
     job.kill() // or procces.kill(job.pid)
  })
  
  
  }
  </code></pre>
  <p>so  I am so confused about managing child processes with nodejs.</p>