notes.dt.in.th

I noticed that my pet Linux VM has become unresponsive after 411 days of uptime (yes, I have never restarted it). Upon further investigation, I found that the problem is caused by stale VS Code server processes running on it, consuming all the CPU. Load average was at around 18.

Usually I would use ps aux | grep to find out which process I should kill, but there are too many processes running. Also, the name of the executable is just node (since VS Code’s extension host runs on Node.js). I have other Node processes running, so I don’t want to run killall node.

Alternatives to “killall” and “ps aux”: “pgrep” and “pkill”

pgrep --full insiders --list-full
  • The above looks for all processes that has insiders in the command line.
  • The --full option is used to match against the full command line (otherwise, the haystack is just node).

Now change pgrep to pkill to kill 'em!

sh killed (pid 421397)
node killed (pid 421405)
node killed (pid 421556)
sh killed (pid 1498875)
node killed (pid 1498883)
sh killed (pid 1537167)
node killed (pid 1537175)
node killed (pid 1537218)
sh killed (pid 1887722)
node killed (pid 1887730)
sh killed (pid 1927803)
node killed (pid 1927811)
node killed (pid 1927839)
sh killed (pid 2035201)
node killed (pid 2035209)
sh killed (pid 2235226)
node killed (pid 2235234)
node killed (pid 2235283)
sh killed (pid 2769072)
node killed (pid 2769080)
node killed (pid 2769117)
sh killed (pid 2788039)
node killed (pid 2788047)
node killed (pid 2788084)
sh killed (pid 3058418)
node killed (pid 3058425)
node killed (pid 3058463)
sh killed (pid 3202723)
node killed (pid 3202731)
sh killed (pid 3251957)
node killed (pid 3251965)
node killed (pid 3252002)
node killed (pid 3259432)
node killed (pid 3259491)
sh killed (pid 3272949)
node killed (pid 3272957)
node killed (pid 3273000)
node killed (pid 3273024)
node killed (pid 3273090)
node killed (pid 3273091)
node killed (pid 3273104)
node killed (pid 3273124)
node killed (pid 3273886)
node killed (pid 3273887)
node killed (pid 3273906)

Yay.