java intercept ctrl c

Java
Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() { /*
       my shutdown code here
    */ }
 });
Source

Also in Java: