Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > signals

Reply
Thread Tools

signals

 
 
Martin A
Guest
Posts: n/a
 
      05-27-2005
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?
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      05-27-2005
Martin A <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
iksrazal@terra.com.br
Guest
Posts: n/a
 
      05-27-2005
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dumping real signals in VCD Sajan VHDL 8 07-21-2007 07:39 AM
Are all the signals read in the process should appear in the sensitivity list of the process? walala VHDL 3 09-09-2003 07:47 AM
generate testbench for array signals Simone Winkler VHDL 1 09-02-2003 04:00 PM
Delay of control signals Ingmar Seifert VHDL 0 08-18-2003 03:21 PM
unused bits in signals Thomas VHDL 2 07-06-2003 10:22 PM



Advertisments