Created
August 17, 2020 03:17
-
-
Save yankooo/d9e2e7c73c23c304d0fac7ef71b3cf4a to your computer and use it in GitHub Desktop.
kill process by pid via port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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