Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4784574
Votes 0
Synopsis background java process dies by CTRL-C on starting shell
Category hotspot:runtime_system
Reported Against 1.3 , 1.3.1 , 1.4.0_00 , 3.5build43 , 3.5build56 , mantis-beta , merlin-beta3
Release Fixed 1.4.0_04, 1.4.1_03(Bug ID:2061691) , 1.4.2(mantis-b19) (Bug ID:2061692) , 1.5(tiger-b03) (Bug ID:2061693)
State 10-Fix Delivered, Needs Verification, bug
Priority: 2-High
Related Bugs 4412451 , 4696207 , 4770335 , 4811663 , 4817957 , 4830313 , 4840407 , 4850355 , 4860964 , 5020307 , 4755829
Submit Date 26-NOV-2002
Description
If I start a java process in background using bourne shell and hit CTRL-C
on the shell prompt, java process dies.

Here is how to reproduce

-- have a bourne shell by typing /bin/sh
-- do javac a.java 
   a.java is listed below
-- run a by typing java a &

   This will return to shell prompt because process was started in background.
Now, hit CTRL-C, java process will die.

--------------
a.java

public class a {
    public static void main(String[] args) {
        while (true) {
            System.out.println("I am in while loop");
        }
    }
}
---------------------------

Please make a note that it happens only with java 1.4 and bourne shell.

Here is the output of java -version command


java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


Work Around
run with -Xrs
  xxxxx@xxxxx   2003-01-10
Evaluation
This is not a mantis bug. Broken in older release.
  xxxxx@xxxxx   2002-11-27

From Engineering:
It looks to me like a shell problem, probably SIGINT is delivered
to the java process when it is printing to the screen and 
being Ctrl-C'ed. I'm not sure if it's allowed or not for shell
to send SIGINT to background process, but VM must exit if it 
receives SIGINT.

Will be closing this bug as will not fix unless an internal escalation is filed to get JPSE team to fix this in older release.


  xxxxx@xxxxx   2002-12-13


Works in next release. JDK 1.4.2  Unless escalated this will not be fixed in
older release.


Still not sure who's bug this is.  When a SIGINT is sent to JVM we must exit.
Sigint is being sent from the bin/sh. Need to talk with some engineers to
look at this one again.  To file an escalation you will need to contact JPSE
team. 
  xxxxx@xxxxx   2003-01-08

Please see workaround.... Bug submitter can re-assign as needed.
  xxxxx@xxxxx   2003-01-10

-----------------------------------
Works ok in 1.4.2b05, not working in 1.4.2b04. Dropped hotspot library from b05
into b04 and still not working. It seems that some change was made in j2se
between b04 and b05 that allowed this to work.

  xxxxx@xxxxx   2003-01-13
-----------------------------------

The fix that went into 1.4.2b05 that caused the SIGINT to be ignored by java is
4747357 - Logging should be initialized lazily. It seems that this fix fixed the
problem by accident. From bug 4747357, "Making the initialization of this package lazy eliminates its loading by the core libraries for non-GUI 
applications.." Running a simple GUI program the problem still exists. This is a
Mantis bug also.

The LogManager adds a shutdown hook which if no hooks already exist eventually
calls Terminator.setup which adds the shutdown hooks for HUP INT and TERM on 
Solaris. It is the INT hook that is causing the problem.

It appears that in csh a background process does not receive the SIGINT signal, 
therefore unmasking it causes no problems. In a bourne shell SIGINT is sent to 
its child processes and by default the background/child process masks this 
signal and subsequently ignores it, so unmasking it through the shutdown hooks 
causes the vm to handle it.

Looks like we need to ignore SIGINT when we are running as a background process.

Also making logging initialization lazy may cause other problems for bugs
such as 4614121, we need to ensure that the shutdown hooks are being added. 

  xxxxx@xxxxx   2003-01-15
-----------------------------------

From man sh:
  The INTERRUPT and QUIT signals for an  invoked  command  are
  ignored  if  the command is followed by &.
  ~~~~~~~
  Because the shell implements both foreground and  background
  jobs  in  the  same process group, they all receive the same
  signals, which can  lead  to  unexpected  behavior.

csh:
  Background jobs are immune  to  signals  generated  from the 
  keyboard, including hangups (HUP). Other signals have  the  
  values  that  the C shell  inherited  from its environment.

  xxxxx@xxxxx   2003-01-15
-----------------------------------

Note this fix (and also the fix for 4755829) has introduced a new problem. With
the fix, no shutdown hook will get executed if the application is started as
a background job from shell script. Please see 4850355 for details.

  xxxxx@xxxxx   2003-04-18
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang