Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2004

Tip: Looking for answers? Try searching our database.

Catching Unix signals?

Thread view: 
John English - 02 Jun 2004 13:07 GMT
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                   | mailto:je@brighton.ac.uk
 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
---------------------------------------------------------------------
Ronny Schuetz - 02 Jun 2004 13:50 GMT
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?forum=4&thread=514860&tstart=30&trange=15

Ciao,
Ronny
Michael Borgwardt - 02 Jun 2004 14:00 GMT
> Is there any way to catch Unix signals inside Java?

No. But there is Runtime.addShutdownHook()
iksrazal - 02 Jun 2004 19:06 GMT
> 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
Andrea Desole - 03 Jun 2004 08:20 GMT
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

>>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
[quoted text clipped - 36 lines]
> http://www.braziloutsource.com/
> iksrazal
iksrazal - 03 Jun 2004 17:20 GMT
> 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/developerworks/ibm/library/i-signalhandling/

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
Thomas Weidenfeller - 04 Jun 2004 08:16 GMT
> 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/faq-sun-packages.html

/Thomas
Andrew Thompson - 04 Jun 2004 10:30 GMT
> All of Sun's SDK documentation contains a link to:

(shakes head)  I missed it Thomas.

> http://java.sun.com/products/jdk/faq/faq-sun-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?   ;-)

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Thomas Weidenfeller - 04 Jun 2004 11:06 GMT
> (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
Andrea Desole - 04 Jun 2004 08:22 GMT
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/faq-sun-packages.html

Andrea

>>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
[quoted text clipped - 13 lines]
> http://www.braziloutsource.com/
> iksrazal


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.