---
title: "Discussion on \"Bash script to kill process on the specified port\" | Hashnode"
description: "Discussion on \"Bash script to kill process on the specified port\". #!/bin/bash\necho Enter port number to kill\nread port_number\npid=\"$(lsof -i:$port_number | awk '{ print $2 }' | sed -n 2p)\"\nkill -9 $pid\necho $?\nHow to run it?\n./killProcessOnPort.sh\nTerminal will ask you the port number to kill.\nand we are good to go..."
url: "https://hashnode.com/posts/bash-script-to-kill-process-on-the-specified-port/60e6e901c32fbd1b737214f6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Bash script to kill process on the specified port](https://jatinpanjwani.hashnode.dev/bash-script-to-kill-process-on-the-specified-port?utm_source=hashnode&utm_medium=feed)

#!/bin/bash echo Enter port number to kill read port\_number pid="$(lsof -i:$port\_number | awk '{ print $2 }' | sed -n 2p)" kill -9 $pid echo $? How to run it? ./killProcessOnPort.sh Terminal will ask you the port number to kill. and we are good to go...

Jul 8, 2021 · 1 min read · jatinpanjwani.hashnode.dev  
Read the article

-   [#bash](https://hashnode.com/tag/bash)
-   [#linux-basics](https://hashnode.com/tag/linux-basics)
-   [#webdev](https://hashnode.com/tag/webdev)

## Written by

[Jatin Panjwani](https://hashnode.com/@jatinScripter)

@jatinScripter

  
[View profile](https://hashnode.com/@jatinScripter)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
