Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

345
Vistas
how do I kill a node.js process from another node.js process?

I'm trying to run scripts/node.js processes from another node.js processes. I figured out how to start them with child_process.spawn() and I have the PID from it but i can't figure out how to kill them. Using child_process.exec() to run taskkill with doesn't work even with/F, even though it says the "task-killing" was successful, the node.js window is stil running. I've even tried powershell's stop-process but that doesn't work either. How do I kill it? (from node.js)

Edit:

Both process.kill(pid,15) and process.kill(pid,9) end with:

Error: kill ESRCH errno: -4040,code: 'ESRCH',syscall: 'kill'

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

NodeJS has a method called kill in the global process object, kill takes a PID (process id) and an optional SIGNAL (kill signal) to send to the process identified by PID.

This is how to use it

process.kill(pid, SIGNAL) -> SIGNAL is optional.

Assuming the process id is 1000

process.kill(1000), not specifying a signal automatically sends SIGTERM to process id 1000.

It should be noted that SIGNAL can also be a number, the number value for SIGTERM is 15. SIGNAL NUMBERS

For example, you can do this.

process.kill(1000, 15) or process.kill(1000, 'SIGTERM') -> sends a terminate signal to process id 1000

process.kill(1000, 9) or process.kill(1000, 'SIGKILL') -> sends a kill signal to process id 1000

Documentation on process.kill.

When pid does not exists, the nodejs process will throw ESRCH.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda