Is there ctrl-c command in cygwin?

2

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!

logoin

Posted 2010-09-09T17:58:34.763

Reputation: 197

If the process is killed, the port will (eventually) time out and be freed – mpez0 – 2010-09-09T19:07:05.623

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 – 2010-09-09T19:17:37.930

Answers

3

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.

Paused until further notice.

Posted 2010-09-09T17:58:34.763

Reputation: 86 075

1

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.

John T

Posted 2010-09-09T17:58:34.763

Reputation: 149 037

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 – 2010-09-09T18:34:42.383

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 – 2010-09-09T22:07:10.417