signals

Discussion in 'Java' started by Martin A, May 27, 2005.

  1. Martin A

    Martin A Guest

    Is it possible for an external program to send a signal (such as SIGINT,
    SIGUSR1, SIGUSR2) to a java application, and have this java application
    handle it?
    Martin A, May 27, 2005
    #1
    1. Advertising

  2. Martin A

    Chris Smith Guest

    Martin A <> wrote:
    > Is it possible for an external program to send a signal (such as SIGINT,
    > SIGUSR1, SIGUSR2) to a java application, and have this java application
    > handle it?


    No, not without JNI.

    For one thing, I don't know how you'd expect to map UNIX signal names to
    other operating systems like Windows or pre-OSX Macintosh. What you can
    do is add shutdown hooks, which will execute before the application
    ends... that amounts to running code in response to delivery of some
    signals on UNIX, but it's limited in terms of what signals work (SIGINT
    and SIGTERM mainly), and you can't stop the VM from exiting. Other
    forms of generic IPC with Java need to be done via IP sockets to be
    portable. If you don't care about portability but still want to avoid
    JNI, then opening a pre-existing named UNIX socket would also work, but
    the Java application could not create that socket.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, May 27, 2005
    #2
    1. Advertising

  3. Martin A

    Guest

    Sure. One caveat, uses sun.misc libs. I've used this code, however,
    since 1.2.1 without problems.

    The instances at the bottom do RMI which is otherwise not shown. Of
    course, -9 can't be caught.

    import java.io.*;
    import sun.misc.*;//for signal catching
    import com.protomatter.syslog.*;

    public class MDDBDriver
    {
    public static void main(String[] args)
    {
    SignalHandler handler = new SignalHandler()
    {
    public void handle(Signal sig)
    {
    Syslog.error(this, "SNIFF_SUPPRESSED Explicit kill sent to
    server process, sig is --> "+sig+", aborting...");
    System.exit(0);
    }
    };
    Signal.handle(new Signal("TERM") , handler);//string appened to SIG,
    meaning SIGTERM

    CRMLogRegister instance1= new CRMLogRegister();
    CRMDBPool instance2= new CRMDBPool();
    MDDBRegister instance3= new MDDBRegister();
    }

    }

    HTH
    iksrazal
    http://www.braziloutsource.com/
    , May 27, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas

    unused bits in signals

    Thomas, Jul 6, 2003, in forum: VHDL
    Replies:
    2
    Views:
    1,063
    Mario Trams
    Jul 6, 2003
  2. Ingmar Seifert

    Delay of control signals

    Ingmar Seifert, Aug 18, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,190
    Ingmar Seifert
    Aug 18, 2003
  3. Simone Winkler

    generate testbench for array signals

    Simone Winkler, Aug 31, 2003, in forum: VHDL
    Replies:
    1
    Views:
    745
    Pedro Claro
    Sep 2, 2003
  4. walala
    Replies:
    3
    Views:
    722
    Allan Herriman
    Sep 9, 2003
  5. Sajan

    Dumping real signals in VCD

    Sajan, Sep 19, 2003, in forum: VHDL
    Replies:
    8
    Views:
    7,111
    vlsi.engg27
    Jul 21, 2007
Loading...

Share This Page