title: Golang - kill process by name
body: <p>What would be an effective way to kill a process with Go code if you only know the process name? I see some functions provided by the <code>os</code> package like:</p>
  
  <pre><code>func FindProcess(pid int) (*Process, error)
  func (p *Process) Kill() error
  func (p *Process) Signal(sig Signal) error
  </code></pre>
  
  <p>Is there a good/common practice to get the <code>pid</code> without having to execute commands and then parse the output?</p>
  
  <p>I have found a way to get back the pid using a command like the following:</p>
  
  <ul>
  <li><code>echo $(ps cax | grep myapp | grep -o '^[ ]*[0-9]*')</code></li>
  </ul>
  
  <p>and I have <a href="https://stackoverflow.com/questions/41037870/go-exec-command-run-command-which-contains-pipe">used it with <code>exec.Command()</code></a> but I would like to avoid it if there is a better approach.</p>