Kill all node processes matching a pattern

If you use Nodemon to run a node application, you may do something like this:

nodemod dist/lectures.js

This loads a parent process, and a couple child Node processes – if one child crashes, the parent restarts them. If you kill the children first, they will be restarted.

When you do this, you get a process ID out, which you can use later. However killing this doesn’t seem to kill the child processes.

Fortunately, you can kill them all at once, like so:

kill -9 $(ps -ef | grep lecture[s] | awk '{print $2}')

Leave a Reply

Your email address will not be published. Required fields are marked *