Skip to content

Instantly share code, notes, and snippets.

@yankooo
Created August 17, 2020 03:17
Show Gist options
  • Save yankooo/d9e2e7c73c23c304d0fac7ef71b3cf4a to your computer and use it in GitHub Desktop.
Save yankooo/d9e2e7c73c23c304d0fac7ef71b3cf4a to your computer and use it in GitHub Desktop.
kill process by pid via port
func Kill(port string) {
output, _ := exec.Command("lsof", "-ti", "TCP:"+port).Output()
pid, err := strconv.ParseInt(strings.Trim(string(output), "\n"), 10, 64)
if err != nil {
return
}
syscall.Kill(int(pid), syscall.SIGTERM)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment