./src/solaris/classes/java/lang/UNIXProcess.java.solaris
Print this page
rev 5754 : [mq]: getPid-patch
*** 23,33 ****
* questions.
*/
package java.lang;
! import java.io.*;
import java.util.concurrent.TimeUnit;
/* java.lang.Process subclass in the UNIX environment.
*
* @author Mario Wolczko and Ross Knippel.
--- 23,46 ----
* questions.
*/
package java.lang;
! import java.io.BufferedInputStream;
! import java.io.BufferedOutputStream;
! import java.io.ByteArrayInputStream;
! import java.io.FileDescriptor;
! import java.io.FileInputStream;
! import java.io.FileOutputStream;
! import java.io.IOException;
! import java.io.InputStream;
! import java.io.OutputStream;
! import java.nio.charset.Charset;
! import java.nio.file.Files;
! import java.nio.file.LinkOption;
! import java.nio.file.Path;
! import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
/* java.lang.Process subclass in the UNIX environment.
*
* @author Mario Wolczko and Ross Knippel.
*** 219,228 ****
--- 232,268 ----
@Override
public synchronized boolean isAlive() {
return !hasExited;
}
+ @Override
+ public int getPid() {
+ if (!isAlive()) {
+ return -1;
+ } else {
+ return pid;
+ }
+ }
+
+ @Override
+ public String getProcessName(int pid) {
+ // look at /proc/<pid>/comm
+ if (pid < 0) {
+ throw new IllegalArgumentException( "pid == " + pid );
+ }
+ Path p = Paths.get( "/proc/" + pid + "/comm" );
+ if (!Files.exists(p, LinkOption.NOFOLLOW_LINKS )) {
+ return null;
+ }
+
+ try {
+ return Files.readAllLines( p, Charset.defaultCharset() ).get(0);
+ } catch (IOException ioex) {
+ throw new RuntimeException( ioex );
+ }
+ }
+
// A FileInputStream that supports the deferment of the actual close
// operation until the last pending I/O operation on the stream has
// finished. This is required on Solaris because we must close the stdin
// and stdout streams in the destroy method in order to reclaim the
// underlying file descriptors. Doing so, however, causes any thread