Totalna pierdoła ale, again, może się komuś przydać: kill_by_port #!/bin/bash # Check if port is provided if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi PORT=$1 # Find the process ID (PID) using the port PID=$(lsof -t -i:$PORT) # Check if a process is using the port if [ -z "$PID" ]; then echo "No process found using port $PORT" exit 0 fi echo "Process using port $PORT found: PID $PID" # Attempt to gracefully terminate the process using SIGQUIT kill -3 $PID echo "Sent SIGQUIT to process $PID. Waiting for termination..." # Wait a moment to give the process time to terminate sleep 2 # Check if the process is still running if ps -p $PID > /dev/null; then echo "Process $PID did not terminate. Sending SIGKILL..." kill -9 $PID echo "Process $PID killed." else echo "Process $PID terminated successfully." fi żeby nie było sam nie napisałe, skorzystałem z ChatGPT - pu...
Blog Tomasza Sandeckiego. Głównie o niczym