added experimental Signals class
[org.ibex.util.git] / src / org / ibex / util / Signals.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.util;
6 import java.io.*;
7 import sun.misc.*;
8
9 /**
10  *  This class uses the highly-proprietary sun.misc.Signal class to
11  *  let the JVM ignore SIGHUP.  This is useful when you want to start
12  *  a JVM and leave it running after you've logged out.
13  */
14 public class Signals {
15     public static void inhibitSigHUP() {
16         Signal.handle(new Signal("HUP"), new SignalHandler () {
17                 public void handle(Signal sig) {
18                     System.out.println("got SIGHUP; ignoring");
19                 }
20             });
21     }
22
23
24     public static void main(String[] s) {
25         inhibitSigHUP();
26         for(;;) {
27             System.out.println("hi");
28             try { Thread.sleep(1000); } catch (Exception e) { }
29         }
30     }
31 }