Kill process by port

Kill process by port

[code lang="bash"]sudo kill -9 (sudo lsof -i:8081 | awk '{print $2}' | tail -n 1)[/code]

คำสั่งนี้เป็นการรวม 2 คำสั่งเข้าด้วยกัน คือ

  1. sudo lsof -i:8081
  2. sudo kill -9

จะเห็นว่า sudo lsof -i:8081 ได้ text เยอะเกิน เราต้องหาวิธี ตัด string
จะได้ว่า sudo lsof -i:8081 | awk ‘{print $2}’ | tail -n 1 (อ่าน command ได้ที่นี่)