How to kill all node processes with the exception of the one running VS Code on Windows

Viewed 868

I'm working with a Ubuntu box, Node, VS Code on Windows.

It's often required to manually kill processes when CTRL-C doesn't properly stop the process, or machine / VSCode has gone to sleep.

A nice solution is to use killall node.

However, this also kills the VSCode window and forces a restart.

How can I kill all node processes minus the one powering VSCode without manually examining each process and finding the correct port / PID??

For instance:

$netstat -lntp | grep node

tcp        0      0 127.0.0.1:545467         0.0.0.0:*               LISTEN      543457/node         
tcp6       0      0 :::1234                 :::*                    LISTEN      345654/node  
   

The tcp connection needs to be maintained as it keeps VS CVode running, but I'd like to kill the tcp6 connection (and any others).

I'm aware that one can find the port, process etc and then manually kill a process, but this is frustrating having to do it every time VSCode become inactive.

How can I run a command (perhaps through an NPM script) that kills all node processes except the one running VSCode?

0 Answers
Related