-1

I have this issue where sometimes .Net Core crashes when I run the debugger in VS Code, and I'm unable to restart the debugger. Even if I quit out of VS Code and go back in, the processes are still open. Rather than restart the machine, I can kill each process manually, but sometimes there are a whole bunch of them, and it gets pretty tedious. For example:

$ ps -eaf | grep dotnet | grep -v grep
16528 ??         0:02.65 /usr/local/share/dotnet/dotnet /Users/ceti-alpha-v/Documents/NGRM/application/NGRM.Web/bin/Debug/netcoreapp2.0/NGRM.Web.dll
16530 ??         0:02.75 /usr/local/share/dotnet/dotnet /Users/ceti-alpha-v/Documents/NGRM/application/NGRM.Web/bin/Debug/netcoreapp2.0/NGRM.Web.dll
16532 ??         0:02.85 /usr/local/share/dotnet/dotnet /usr/local/share/dotnet/sdk/2.1.403/Roslyn/bincore/VBCSCompiler.dll

$ kill 16528 16530 16532

I'd like to delete the processes automatically with a single command, but I'm not sure how to pipe each PID to kill.

Ringo
  • 5,097
  • 3
  • 31
  • 46
  • 1
    https://stackoverflow.com/questions/22334761/osx-terminal-how-to-kill-all-processes-with-the-same-name – mbj Jan 04 '19 at 10:18

2 Answers2

3

You can use xargs like this

ps -eaf | grep dotnet | grep -v "grep" |  awk '{print $2}' | xargs kill

or if you want to just kill all dotnet processes

killall dotnet
Jan Gassen
  • 3,406
  • 2
  • 26
  • 44
  • Both `pkill` and `killall` worked for me. But good to know the awk way of doing it, too! – Ringo Jan 04 '19 at 10:27
1

You can use command Substitution

kill $(ps -eaf | grep dotnet | grep -v grep | awk '{ print $2 }')
Vencat
  • 1,272
  • 11
  • 36