United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4244896 : (process) Provide Process.waitFor(timeout), Process.destroyForcibly() and Process.isAlive()

Details
Type:
Enhancement
Submit Date:
1999-06-08
Status:
Closed
Updated Date:
2014-05-07
Project Name:
JDK
Resolved Date:
2012-09-10
Component:
core-libs
OS:
generic,windows_xp,windows_2000
Sub-Component:
java.lang
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.2.1,1.2.2,1.3.0,1.4.2
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

Description
Name: vi73552			Date: 06/08/99


Hi,

RFE: Needs getPid(), getEnvVar(), killProcess(String pid) From the java.lang.System class 

1. getPid() => shuld able to give the process id of the jvm process 
it is running in (java.exe)

2. getEnvVar() => shuld able to return either Windows/Unix Environment 
Variable
[for this, please see bug 4199068]

3. killProcess(String pid) => shuld kill the process given the pid
if the process has permissions to do so

This  functions are important and avialable in the two most popular 
os's windows and unix. In case if a particular os does not have support
for this two calls you can return UnSupportedMethodExcetion.

In our server development lot of times we needed these functions
we wrote a jni C wrapper to get this values which will make the code
not 100% pure java code

Please let me know if you need any further info 

Thanks,
Rama Krishna
###@###.###
(Review ID: 84103) 
======================================================================

Name: rmT116609			Date: 06/10/2003


A DESCRIPTION OF THE REQUEST :
There are some ways for checking for a running application's instance (creating lock file, creating a listening socket, RMI invocation) but they are all unnecessary unsecure (socket, RMI) or typically unsafe (lock file -- since you can remove it under Unices).
Since Windows'es are supporting PIDs/mutexes, there is a uniform possibility to check for single instance -- create a PID file. Unfortunately, there is no way to get PID for running Java app from Java itself.

JUSTIFICATION :
It would be a great improvement to integrate a getPID() method. It can be also useful for some other purposes.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Something like this:
(int) java.lang.System.getPID();
(Review ID: 187540)
======================================================================

                                    

Comments
EVALUATION

We now appreciate the pragmatic need for much of this functionality even though it is inherently platform specific.

###@###.### 2003-01-10

Environment variable support is being implemented as a separate RFE.
I am removing the request for getEnvVar() from the synopsis for this RFE.
It currently looks unlikely we will address support for PIDs in Tiger,
so I am de-committing this bug for Tiger.
###@###.### 2003-08-11
                                     
2003-08-11
WORK AROUND

Name: skT45625			Date: 07/11/2000


Create native code using JNI for each platform being used, very difficult
solution.
(Review ID: 107079)
======================================================================
                                     
2004-09-15
WORK AROUND

An easier solution than JNI is to use an external program, e.g.
perl -e 'print getppid()'
and capture the output of that.
                                     
2006-01-10
EVALUATION

A minimal and safe design to ease the life of folks writing script-like code in Java,
I suggest:

/** Returns a string identifying the current process. */
String System.getpid();

/** Returns a string identifying the subprocess. */
String Process.getpid();

The intent is that the returned Strings can be used in operating system
commands (like Unix "kill") that operate on processes.
                                     
2008-01-25
EVALUATION

http://hg.openjdk.java.net/hsx/hotspot-comp/jdk/rev/ff0da4ea08a2
                                     
2012-08-14
How about splitting out the System.getPID() part of this bug into a bug that can be handled separately?
                                     
2012-11-15
SQE has looked at the bug and decided no additional tests are needed
                                     
2013-09-05



Hardware and Software, Engineered to Work Together