Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Suppose I have starting 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?

share|improve this question
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
add comment

3 Answers 3

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:~$
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:~$

and

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

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
     UID     PID    PPID TTY     STIME COMMAND
    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
-bash
tony:~$
tony:~$ cat /proc/2700/exename
/cygdrive/c/Windows/system32/java

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

share|improve this answer
    
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
add comment

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.

share|improve this answer
1  
as can the native taskkill /f /im procname.exe –  Marcos Feb 28 '12 at 12:51
add comment

There is a procps package in cygwin that you can install to get the same functionality with the same commands.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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