How to stop Grunt
If it's a task that you currently running you can stop it with
ctrl + c
If it's a task that is running in background you can find his process id (pid) with
ps aux | grep grunt
and then kill it withkill {pid}
One liner to kill the currently running grunt task:
kill -9 $(ps aux | grep -v "grep" | grep grunt | awk '{print $2}')
Explanation:
Kill is the command to end a process
The -9 option is used to ensure the process is actually killed if it's stuck in a loop
ps -aux lists the currently running processes
grep -v "grep" excludes any lines with the word grep so we don't kill the current grep command that we are running
grep grunt just returns the line with grunt
And finally awk '{print $2}' returns the number in the second column that is the pid. This is what is passed to kill.
In Powershell, run the Get-Process cmdlet, to list all processes, or with a comma-separated list to filter (wildcards work too). Its alias is ps
. For example:
Get-Process grunt, node
or
ps grunt, node
Once you determine the process ID (third column from the right, 'Id'), then you can use Stop-Process to end it. Its alias is kill
. For example:
Stop-Process 2570
or
kill 2570
I'm posting this because the question and a commenter asks for a Windows, and grep
doesn't work on my Windows 10 install, and its Powershell equivalent, Select-String, doesn't satisfactorily return the full process information. Luckily Get-Process has its own filtering!
A shorter solution with a nifty trick like Felix Eve's:
kill -9 $(ps -aux | grep "[g]runt" | awk '{print $2}')
The []
avoids having the word 'grunt' in the grep, so it won't get accidentally deleted.