JDK-4244896 : (process) Provide Process.waitFor(timeout), Process.destroyForcibly() and Process.isAlive()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.2.1,1.2.2,1.3.0,1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 1999-06-08
  • Updated: 2017-05-16
  • Resolved: 2012-09-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 8
8 b47Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
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
SQE has looked at the bug and decided no additional tests are needed
2013-09-05

How about splitting out the System.getPID() part of this bug into a bug that can be handled separately?
2012-11-15

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/jdk/rev/ff0da4ea08a2
2012-08-14

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

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

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

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