Files
fn_registry/bash/functions/infra/port_kill.md
T
egutierrez cfdf515228 chore: auto-commit (799 archivos)
- .claude/CLAUDE.md
- .claude/commands/subagentes.md
- .claude/rules/INDEX.md
- .mcp.json
- bash/functions/cybersecurity/analyze_dns.md
- bash/functions/cybersecurity/audit_http_headers.md
- bash/functions/cybersecurity/audit_ssh_config.md
- bash/functions/cybersecurity/check_firewall.md
- bash/functions/cybersecurity/detect_suspicious_users.md
- bash/functions/cybersecurity/encrypt_file.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 00:28:20 +02:00

2.1 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
port_kill function bash infra 1.0.0 impure port_kill(port: int, signal: string) -> void Mata los procesos que escuchan en un puerto TCP dado. Idempotente: si no hay proceso en el puerto retorna exit 0. Hace un segundo intento con SIGKILL si el primer intento con signal no libera el puerto.
port
kill
process
tcp
pendiente-usar
false error_go_core
name desc
port Numero de puerto TCP (1-65535) cuyos procesos en estado LISTEN seran terminados.
name desc
signal Signal opcional para kill. Default TERM. Acepta KILL, INT, TERM, HUP o numerico (9, 15, ...). Si el proceso sobrevive, se reintenta automaticamente con KILL.
Imprime a stdout una linea por cada PID matado (KILLED pid=X signal=Y port=Z) o NO_PROCESS si el puerto ya estaba libre. Errores a stderr. Exit codes: 0=OK, 2=puerto invalido, 3=puerto sigue ocupado tras SIGKILL, 4=permiso denegado, 5=ni lsof ni fuser disponibles. false
bash/functions/infra/port_kill.sh

Ejemplo

source bash/functions/infra/port_kill.sh

# Matar proceso en puerto 8080 con SIGTERM (default)
port_kill 8080

# Matar proceso en puerto 3000 con SIGKILL directo
port_kill 3000 KILL

Notas

Idempotente: si ningun proceso escucha en el puerto, imprime NO_PROCESS port=<port> y retorna 0 sin error.

Preferencia de herramienta: usa lsof -ti tcp:<port> -sTCP:LISTEN si esta disponible; fallback a fuser -n tcp <port>. Si ninguno esta instalado, retorna exit 5.

Logica de reintento: tras enviar la signal inicial espera 2 segundos. Si el puerto sigue ocupado y la signal no era KILL/9, realiza un segundo intento con SIGKILL. Si tras ese segundo intento el puerto sigue bloqueado, retorna exit 3.

Permisos: si los PIDs pertenecen a root y el invocador no tiene privilegios, kill fallara y se reporta PERMISSION_DENIED pid=<pid> a stderr con exit 4. Ejecutar con sudo si es necesario.