TL;DR: wmic process get ProcessID, Commandline /format:csv | tr -d '\r' | grep -- 'search term' | awk -F, '{ print $NF }' | xargs /bin/kill -f -W
I had a more challenging situation than most answers considered: killing the Windows process by executable name (node.exe) was too broad so I had to find the WINPID by looking at the command line arguments. And unfortunately, the cygwin ps command doesn't show commandline arguments.
Another challenge was, although my process was spawned in cygwin, it created child processes that couldn't be seen in any ps except ps -W.
As an aside, you can find command line arguments for your visible cygwin processes by running this: grep -a "" /proc/*/cmdline | xargs -0 But that didn't help me in this situation because the process I wanted to kill wasn't visible by cygwin and therefore wasn't in that output.
Fortunately, Windows (10, at least) comes with a command line tool you can run in cygwin to get command name and argument information. Here's how: wmic process get ProcessID, Commandline /format:csv. The output looks something like this:
DESKTOP-ABC,E:\Windows\system32\lxss\wslhost.exe {xxx} x y z {xxx},180
DESKTOP-ABC,\??\E:\Windows\system32\conhost.exe 0x6,2295
DESKTOP-ABC,E:\Windows\system32\svchost.exe -k ClipboardSvcGroup -p -s abcdef,430
The last column of that output is the Windows process ID.
Other answers here claim you can /bin/kill -f $WINPID those, but when I tried, it reported this error: kill: illegal pid: $WINPID. I suspect this has something to do with cygwin not running in administrator mode? [No, this was not why, see my update below, but it is written in a way that assumes you've read the original first.*]
Original Answer (1/3/2023)
Additional answers say to taskkill /pid $WINPID but when I tried, it reported this error: ERROR: Invalid query. But this line from @244an's answer worked for me: taskkill /F /PID $WINPID /T.
I decided to post this as a separate answer because, in my humble opinion, the information I've written above is just as valuable as @244an's answer, and I have more to say. taskkill provides a variety of ways to get the Windows PID from the cygwin command line even if the process isn't visible in cygwin.
I also want to say it was challenging to figure out how to pass a variable into taskkill due to line return issues. wmic, being a Windows command, returns Windows line endings (\r\n). Cygwin assumes its commands are going to receive unix endings (\n). Due to this, taskkill outputs some very unhelpful error messages. The tr in this pipeline is how I resolved that:
wmic process get ProcessID, Commandline /format:csv | tr -d '\r' | grep -- 'search term' | awk -F, '{ system("taskkill /F /PID " $NF " /T") }'
It removes every '\r' from the output. awk -F, means the field separator for every column is a comma. The rest of the awk command says, "for every line grep finds, run taskkill on the last column (i.e., $NF) of the csv output.
Updated Answer (1/3/2024)
*: As @Roy pointed out in a comment, this was probably because I was not including the -W flag. In other words, I should've typed /bin/kill -f -W $WINPID instead of /bin/kill -f $WINPID.
Here's another important aside: I didn't even know -W existed because it never came up in the man page or kill's usage message. Another comment explains why, but I couldn't understand it (until today):
Make sure you use /bin/kill, the bash builtin kill doesn't have the -f switch. Using /bin/kill seems to work on git-bash, msys2 and cygwin.
Here's my understanding: if you type kill on the command line when using bash with cygwin, it uses the bash builtin. That is not the same as /bin/kill: /bin/kill is a cygwin command, and it's the one that has the -f and -W flags.
It turns out /bin/kill -f -W $WINPID is even better than taskkill /F /PID $WINPID /T. Today, it allowed me to kill a process that taskkill /F /PID $WINPID /T couldn't. It also simplifies the script at the end of my original answer. Now it looks like this:
wmic process get ProcessID, Commandline /format:csv | tr -d '\r' | grep -- 'search term' | awk -F, '{ print $NF }' | xargs /bin/kill -f -W