I have a process running in cygwin and using a port. When I kill the process in another cygwin window by issuing command:

kill -9 PID   or  /bin/kill -f PID

I can see the process got terminated. However, the port is not released. Usually I can terminate the process cleanly by using ctrl-c. Is there a kill command that can have the same effect as ctrl-c in cygwin? Thanks!

link|improve this question

75% accept rate
If the process is killed, the port will (eventually) time out and be freed – mpez0 Sep 9 '10 at 19:07
It seems like the process is killed. Nothing shows up when I grep it. But I can see it in Windows Task Manager that the process is still running. In this case, the process is java.exe. If I end the process in Task Manager, the port is released instantly. – logoin Sep 9 '10 at 19:17
feedback

2 Answers

Ctrl-C is a SIGINT I believe (signal interrupt), which would be equivalent to:

kill -2 PID

It's definitely lighter than a kill -9 as it will give the process some time to clean up after itself.

For more info see man kill.

link|improve this answer
I tried this command. It looks like the process is terminated but the port is still in used. Is there a way to make sure the port is released when the process is killed? Thanks! – logoin Sep 9 '10 at 18:34
Cygwin can still run batch scripts, you know :) Make your own kill implementation and add it to your path. In the script you can use something as simple as taskkill /T /PID %1 @logoin – John T Sep 9 '10 at 22:07
feedback

kill -9 should only be used as a last resort. If kill -SIGNINT PID isn't doing what you want, try kill -SIGTERM PID. These signals can be trapped by the application and it can do what it wants with them including performing cleanup or ignoring them.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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