Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Catching Unix signals?

Reply
Thread Tools

Catching Unix signals?

 
 
John English
Guest
Posts: n/a
 
      06-02-2004
Is there any way to catch Unix signals inside Java? I've tried a little
test program that catches Throwable, but using "kill -SIGHUP" or "kill
-SIGQUIT" just kills the app dead, with no opportunity for me to do any
cleaning up prior to the application terminating.

---------------------------------------------------------------------
John English | (E-Mail Removed)
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
School of Computing Maths & IS | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
---------------------------------------------------------------------

 
Reply With Quote
 
 
 
 
Ronny Schuetz
Guest
Posts: n/a
 
      06-02-2004
John English wrote:

Hi,

> Is there any way to catch Unix signals inside Java? I've tried a little
> test program that catches Throwable, but using "kill -SIGHUP" or "kill
> -SIGQUIT" just kills the app dead, with no opportunity for me to do any
> cleaning up prior to the application terminating.


http://forum.java.sun.com/thread.jsp...t=30&trange=15

Ciao,
Ronny
 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      06-02-2004
John English wrote:
> Is there any way to catch Unix signals inside Java?


No. But there is Runtime.addShutdownHook()
 
Reply With Quote
 
iksrazal
Guest
Posts: n/a
 
      06-02-2004
John English <(E-Mail Removed)> wrote in message news:<c9kfk7$8k1$(E-Mail Removed)>...
> Is there any way to catch Unix signals inside Java? I've tried a little
> test program that catches Throwable, but using "kill -SIGHUP" or "kill
> -SIGQUIT" just kills the app dead, with no opportunity for me to do any
> cleaning up prior to the application terminating.


This is from a while back - but I just compiled it with jdk1.4.2 . 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

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal
 
Reply With Quote
 
Andrea Desole
Guest
Posts: n/a
 
      06-03-2004
I'm not sure this is always guaranteed to work. As far as I remember
only the java.* and javax.* classes should be used. The others are for
internal use only

Andrea

iksrazal wrote:
> John English <(E-Mail Removed)> wrote in message news:<c9kfk7$8k1$(E-Mail Removed)>...
>
>>Is there any way to catch Unix signals inside Java? I've tried a little
>>test program that catches Throwable, but using "kill -SIGHUP" or "kill
>>-SIGQUIT" just kills the app dead, with no opportunity for me to do any
>>cleaning up prior to the application terminating.

>
>
> This is from a while back - but I just compiled it with jdk1.4.2 . 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
>
> Outsource to an American programmer living in brazil!
> http://www.braziloutsource.com/
> iksrazal

 
Reply With Quote
 
iksrazal
Guest
Posts: n/a
 
      06-03-2004
Andrea Desole <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> I'm not sure this is always guaranteed to work. As far as I remember
> only the java.* and javax.* classes should be used. The others are for
> internal use only
>
> Andrea
>


Its worked for me since jdk 1.2.2 to jdk1.4.2 , and is explained
nicely from IBM here:

http://www-106.ibm.com/developerwork...ignalhandling/

That being said, I'd like to see a link explaining Sun's position on
using jdk classes outside of java.* and javax.* , such as sun.misc.* .

Outsource to an American programmer living in brazil!
http://www.braziloutsource.com/
iksrazal
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-04-2004
iksrazal wrote:
> That being said, I'd like to see a link explaining Sun's position on
> using jdk classes outside of java.* and javax.* , such as sun.misc.* .


All of Sun's SDK documentation contains a link to:

http://java.sun.com/products/jdk/faq...-packages.html


/Thomas
 
Reply With Quote
 
Andrea Desole
Guest
Posts: n/a
 
      06-04-2004
Well, I have to say that I don't really find Sun very explicit about
this, but it is possible to find something. Try this page

http://java.sun.com/products/jdk/faq...-packages.html

Andrea


iksrazal wrote:
> Andrea Desole <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
>
>>I'm not sure this is always guaranteed to work. As far as I remember
>>only the java.* and javax.* classes should be used. The others are for
>>internal use only
>>
>>Andrea
>>

>
>
> Its worked for me since jdk 1.2.2 to jdk1.4.2 , and is explained
> nicely from IBM here:
>
> http://www-106.ibm.com/developerwork...ignalhandling/
>
> That being said, I'd like to see a link explaining Sun's position on
> using jdk classes outside of java.* and javax.* , such as sun.misc.* .
>
> Outsource to an American programmer living in brazil!
> http://www.braziloutsource.com/
> iksrazal

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-04-2004
On Fri, 04 Jun 2004 09:16:05 +0200, Thomas Weidenfeller wrote:

> All of Sun's SDK documentation contains a link to:


(shakes head) I missed it Thomas.

> http://java.sun.com/products/jdk/faq...-packages.html


In fact I remember somebody pointing
that link out to me (probably you)
and went *searching for it* at Sun but
failed to locate it (too many hits for
'sun package' and could not think how
to narrow down)..

If it is there.. it might be it is
buried amongst hundreds (thousands?)
of other links in the SDK..

Or is it one of those 'hidden in small
print around the edges of the web-page'
kind of links?

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-04-2004
Andrew Thompson wrote:
> (shakes head) I missed it Thomas.

[...]
> If it is there.. it might be it is
> buried amongst hundreds (thousands?)
> of other links in the SDK..


It is on the "front page" of the SDK documentations. E.g. on

http://java.sun.com/j2se/1.5.0/docs/
http://java.sun.com/j2se/1.4.2/docs/
http://java.sun.com/j2se/1.3/docs/

The link is always labeled

Note About sun.* Packages

> Or is it one of those 'hidden in small
> print around the edges of the web-page'
> kind of links?


Nop. normal link.


/Thomas
 
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
Catching system signals (UNIX). Viacheslav Chumushuk Ruby 1 01-15-2009 08:24 AM
How to catching loading exception? Bob ASP .Net 5 02-19-2005 07:07 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM



Advertisments