JDK-4717969 : (process) Control-C does not end forked Java process (w2k, wnt)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0,1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-07-20
  • Updated: 2015-10-19
  • Resolved: 2015-10-19
Related Reports
Relates :  
Description
Name: gm110360			Date: 07/19/2002


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)


FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

ADDITIONAL OPERATING SYSTEMS :
Microsoft Windows NT


A DESCRIPTION OF THE PROBLEM :
When indirectly (e.g., through Ant) starting a Java process
in the original Windows console (DOS prompt) or in a third-
party console such as Cygwin, only the directly started
process can be killed by pressing Control-C.

That is, as can be seen in the Windows Task Manager, the
indirectly started process still runs and can therefore not
be restarted if it listens to a specific socket, or delete
(at start-up time) a temporary file it created, ...

Now this behaviour ("child" process being fully independent
of "parent" process") may be desired. The real problem is
that sometimes, when trying to End [the Java] Process in
the Task Manager, an "infinite" number of Java processes
are started so that the computer gets clogged and a
hardware reset is needed!


REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. run ControlCProblemDemo a couple of times (kill it with
Control-C between runs) and note how the example file can
always be deleted
2. now run ExecuteControlCProblemDemo a couple of times
(kill it with Control-C between runs) and note how the
example file can no longer be deleted
3. consult the Task Manager to see that there are still
Java processes running
4. try to kill these processes with End Process


EXPECTED VERSUS ACTUAL BEHAVIOR :
In Java 1.3 killing a "parent" process also kills
the "child" process. In Java 1.4 this is not the case.

When killing a Java process in the Task Manager it should
not go beserk by forking an infinite number of Java
processes.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;

public
class ExecuteControlCProblemDemo
{
    public
    static
    void
    main( String[] args )
    {
        try {
            Runtime.getRuntime().exec( "java ControlCProblemDemo" );
            while ( true );
        } catch( IOException ioe ) {
            System.err.println( ioe );
        }
    }
}


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public
class ControlCProblemDemo
{
    public
    static
    void
    main( String[] args )
    {
        File file = new File( "controlCProblemDemo" );
        if ( file.exists() ) {
            System.out.println( "deleted controlCProblemDemo=" + file.delete
() );
        }
        (new Thread( new ControlCProblemRunnable( file ) )).run();
        while ( true );
    }


    private
    static
    class ControlCProblemRunnable
        implements Runnable
    {
        private File file;


        public
        ControlCProblemRunnable( File file )
        {
            this.file = file;
        }


        public
        void
        run()
        {
            try {
                FileWriter fileWriter = new FileWriter( file );
                fileWriter.write( "Control-C Problem Demo" );
                fileWriter.flush();
                while ( true );
            } catch( IOException ioe ) {
                System.err.println( ioe );
            }
        }
    }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Log out of Windows and then log in again instead of trying
to End [the Java] Process through the Task Manager.
(Review ID: 158533) 
======================================================================

Comments
The interactions with shells are complex and the desired behavior is not clear.
19-10-2015

EVALUATION This is a common problem on Windows. Note that the Cygwin environment has the same problem -- that Control-C only kills the immediate child process, but not its descendants. There may be some unwanted interaction with process creation flags; See the documentation for CREATE_NEW_PROCESS_GROUP in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_creation_flags.asp (But we don't set that flag!) It may be that fixing this will cause other unwanted behavior, like the dreaded "popping up an empty unused console window" bug. It may be that the code that calls CreateProcess should adjust the creation flags based on whether there is a current console. A difficult bug.
17-11-2005

EVALUATION Probabaly a duplicate of bug 4614552. -- iag@sfbay 2003-04-04
04-04-2003