Suppose I have started my process like:

java -DSOME_STRING -jar foo.jar

Then on linux, I can use the following to find or kill this process:

pgrep -f SOME_STRING
pkill -f SOME_STRING

However this doesn't seem to work on cygwin. Can anyone suggest an alternative for these tools in cygwin?

  • 1
    Doesn't work in what way? Doesn't kill the process, doesn't find the process to kill it? Gives an error? – EightBitTony Aug 24 '11 at 21:51
  • pgrep doesn't find the process. pkill doesn't kill the process. – toolkit Aug 25 '11 at 20:48
  • Here are implementations of killall and pidof crafted for Cygwin. Depends on Python 2/ - github.com/kata198/cygwin-ps-misc – Tim Savannah Nov 25 '14 at 16:28

pkill and pgrep certainly exist within Cygwin, in the procps package (you can search cygwin packages here).

It appears to work for me,

tony:~$ nohup sleep 100983 &
[1] 5476
tony:~$ nohup: ignoring input and appending output to `nohup.out'
tony:~$ ps -ef | grep sleep
    tony    5476    2696   2  23:28:53 /usr/bin/sleep
tony:~$ pkill -f sleep
[1]+  Terminated              nohup sleep 100983


tony:~$ nohup sleep 837746 &
[1] 228
tony:~$ nohup: ignoring input and appending output to `nohup.out'
tony:~$ pgrep -f 837746
tony:~$ pkill -f 837746
[1]+  Terminated              nohup sleep 837746

Update: okay, tested with java. Executing java from the Cygwin command line does not result in the java string being placed into /proc/<pid>/cmdline, that just contains -bash. This appears to be a limitation of Cygwin.

tony:~$ java -Dsomething=valid -jar Captor.jar &
[1] 2700
tony:~$ ps -ef
    tony    4164       1   ?    Aug 21 /usr/bin/mintty
    tony    4676    4164   0    Aug 21 /usr/bin/bash
    tony    5776    4676   0    Aug 23 /usr/bin/ssh
    tony    5148       1   ?  23:53:03 /usr/bin/mintty
    tony    5332    5148   1  23:53:03 /usr/bin/bash
    tony    5816       1   ?  00:04:16 /usr/bin/mintty
    tony    5432    5816   2  00:04:16 /usr/bin/bash
    tony    2700    5432   2  00:04:34 /cygdrive/c/Windows/system32/java
    tony    2232    5432   2  00:04:39 /usr/bin/ps
tony:~$ pgrep -f something
tony:~$ cat /proc/2700/cmdline
tony:~$ cat /proc/2700/exename

I suspect therefore, the answer is you can't do this with a Cygwin tool, you would need a Windows specific tool.

  • Your example is substantially different than the one the OP is trying. You matched the name of the process rather than an arbitrary string in it's arguments. Can you test the latter and see if that works? – Caleb Aug 25 '11 at 5:21
  • seems to work fine – EightBitTony Aug 25 '11 at 7:06
  • It seems procps is not available for x64 cygwin. – thameera Oct 15 '13 at 5:57
  • 1
    @thameera try package procps-ng. – Abdull Sep 22 '16 at 8:54
  • 1
    apt-cyg install procps-ng with newest cygwin – Timo Nov 20 '17 at 15:09

The Cygwin utilities work like the Linux ones, but they only work on Cygwin processes. For Windows processes, you need to use Windows utilities, such as the ones from Sysinternals. PsKill can kill processes by name.

  • 4
    as can the native taskkill /f /im procname.exe – Marcos Feb 28 '12 at 12:51
  • 2
    ps also shows Windows processes with the -W switch – golimar Dec 11 '14 at 17:00

In older Cygwin versions, there is a procps package that you can install to get the same functionality with the same commands.

In newer Cygwin versions, the procps package no longer exists and is replaced by package procps-ng.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.