Java error: java.lang.IllegalArgumentException: signal already used by VM: INT

I am studying the Java problem (using IBM JVM 1.4.2 64-bit) on Red Hat Linux. I am wondering if anyone has seen this error message before and knows if there is a way around the problem?

Source:

import sun.misc.Signal;
import sun.misc.SignalHandler;

public class SignalTest extends Thread
{
    private static Signal signal = new Signal("INT");

    private static ShutdownHandler handler = new ShutdownHandler();

    private static class ShutdownHandler implements SignalHandler
    {
        public void handle(Signal sig)
        {
        }
    }

    public static void main(String[] args)
    {
        try
        {
            Signal.handle(signal, handler);
        }
        catch(Throwable e)
        {
            e.printStackTrace();
        }

        try { Thread.sleep(5000); } catch(Exception e) { e.printStackTrace(); }

        System.exit(0);
    }
}

Output:

java.lang.IllegalArgumentException <Signal already used by VM: INT>
java.lang.IllegalArgumentException: Signal already used by VM: INT
at
com.ibm.misc.SignalDispatcher.registerSignal(SignalDispatcher.java:145)
at sun.misc.Signal.handle(Signal.java:199)
at xxx

Additional Information:

I found out something strange. The reason this fails is because I am running the program inside the shell script as a background process.

i.e. sigtest.sh:

#!/bin/bash
java -cp . SignalTest >> sigtest.log 2>&1 &

If I run the program from the command line or delete "&" (ie make it foreground inside the shell script), it has no problem ... I don’t understand why this is so.

+5
source share
8 answers

, JVM. / API (sun.misc.Signal/SignalHandler), API .

IBM JVM -, SUN JVM , , . , SUN JVM, IBM JVM.

( ):

JVM // .

  • -Xrs /
  • ibm.signalhandling.sigint true/false
  • ibm.signalhandling.rs true/false

(, Google , )

, IBM JVM , , SUN JVM, -, linux/solaris

-XX:-AllowUserSignalHandlers

, . :

, IBM JVM ( , ). :

Java


, , IBM JVM SIGINT, SIGINT .

Btw. -Xrs , , . :

-Xrs Sun JVM, SIGINT, SIGTERM, SIGHUP SIGQUIT JVM .

, JVM . JVM, .

+3

JVM -Xrs, IBM JVM this . .

: :

Runtime.getRuntime(). addShutdownHook (Thread)

, (, -Xrs ). (, Runtime) , , .

+2

Heinz Kabutz, , , , , JVM, os/jvm , . , os/vm .

, Yishai, .

+1

- , VM , SIGINT. , / , , .

0

, . , - .

System.out.println("Hello");

handle :

z@zolty:/tmp/so$ java SignalTest & sleep 1s && kill -2 $!
[1] 20467
z@zolty:/tmp/so$ Hello
z@zolty:/tmp/so$
z@zolty:/tmp/so$ java SignalTest
[1]+  Done             java SignalTest
0

, , JVM (SuSE) IBM. , JVM .

0

. java- ksh script. script , csh /etc/passwd

userx: *: 7260: 20:://userx:/USR//CSH

script . , sh, .

, , unix csh.

0

IBM JVM (64 ) Linux. , JVM , .

> grep Sig /proc/self/status
SigQ:   1/1030663
SigPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000001001006
SigCgt: 0000000000000000

Note that the bit for SIGINT (value 2) is set to SigIgn. When starting the IBM JVM with this mask, it refuses to install a handler for SIGINT. I worked on the problem by running the JVM through the Python shell, which resets the default SIGINT handler:

#!/usr/bin/env python

import os
import signal
import sys

signal.signal(signal.SIGINT, signal.SIG_DFL)

args = sys.argv[1:]
os.execv(args[0], args)

The first argument to the shell is the command java, then follow the arguments to the JVM.

0
source

All Articles