I am creating a TFTP server and keep it running using a infinite loop. When i try to send a kill signal
/bin/kill -s SIGINT <pid>
I want Java process to close TFTP server and exit.
class TFTP {
public void startTFTP(String str, String str1){
try {
//Start TFTP server
// Both of below are not working.
Runtime.getRuntime().addShutdownHook(new Thread(){
@Override
public void run(){
//Shutdown tftp server
System.out.println("Exiting");
System.exit(0);
}
});
SignalHandler handler = new SignalHandler () {
public void handle(Signal signal) {
System.exit(0);
}
};
Signal.handle(new Signal("INT"), handler);
Signal.handle(new Signal("TERM"), handler);
while(true){
// Infinite loop to keep process running.
}
}
} catch (Exception e) {
}
}
public static void main(String args[]){
TFTP tftp = new TFTP();
tftp.startTFTP(args[0],args[1]);
}
}
I kill the process from a script and calling
/bin/kill -s SIGINT <pid>
doesn't kill the java process for some reason. I thought SIGINT is handled as part of
Signal.handle(new Signal("INT"), handler);
What am i missing here?
Regards
Dheeraj Joshi