How to combine "lsof -i :port" and "kill pid" in bash
Asked Answered
S

3

18

How do i combine these two commands in the bash:

lsof -i :port
kill pid

The first one returns the PID i want to kill to release the port. The second one kills the returned PID.

I am doing this because I don´t know of any way to kill a jetty webserver within the Netbeans IDE on OSX. Is there a way?

Schnauzer answered 13/10, 2015 at 11:39 Comment(0)
H
43

You can use $():

kill $(lsof -t -i:port)
Hallock answered 13/10, 2015 at 11:44 Comment(1)
How can I make this into an alias command? Like alias k4="kill $(lsof -t -i:port)"?Whitacre
R
12

You can use

kill -9 `lsof -t -i:port`
Ridglea answered 8/3, 2018 at 17:36 Comment(1)
Thank you for this code snippet, which might provide some limited short-term help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you've madeValuator
P
0

You can use this

kill $(lsof -ti:3000)
Polythene answered 7/5 at 15:49 Comment(1)
Only subtly different, if you don't want this answer delete as a duplicate answer, please explain how this is better.Aborning

© 2022 - 2024 — McMap. All rights reserved.