|
61 | 61 | import java.nio.channels.ReadableByteChannel;
|
62 | 62 | import java.nio.channels.SeekableByteChannel;
|
63 | 63 | import java.nio.channels.WritableByteChannel;
|
64 |
| -import java.nio.file.Files; |
65 | 64 | import java.nio.file.LinkOption;
|
66 |
| -import java.nio.file.Path; |
67 |
| -import java.nio.file.Paths; |
68 | 65 | import java.nio.file.StandardCopyOption;
|
69 | 66 | import java.nio.file.StandardOpenOption;
|
70 | 67 | import java.nio.file.attribute.FileAttribute;
|
|
85 | 82 | import java.util.Set;
|
86 | 83 | import java.util.concurrent.TimeUnit;
|
87 | 84 |
|
| 85 | +import org.graalvm.nativeimage.ImageInfo; |
| 86 | +import org.graalvm.nativeimage.ProcessProperties; |
| 87 | + |
88 | 88 | import com.oracle.graal.python.PythonLanguage;
|
89 | 89 | import com.oracle.graal.python.builtins.Builtin;
|
90 | 90 | import com.oracle.graal.python.builtins.CoreFunctions;
|
@@ -420,8 +420,11 @@ public abstract static class GetPidNode extends PythonBuiltinNode {
|
420 | 420 | @Specialization(rewriteOn = Exception.class)
|
421 | 421 | @TruffleBoundary
|
422 | 422 | long getPid() throws Exception {
|
423 |
| - Path path = Paths.get("/proc/self/stat"); |
424 |
| - return Long.parseLong(new String(Files.readAllBytes(path)).trim().split(" ")[0]); |
| 423 | + if (ImageInfo.inImageRuntimeCode()) { |
| 424 | + return ProcessProperties.getProcessID(); |
| 425 | + } |
| 426 | + TruffleFile statFile = getContext().getPublicTruffleFileRelaxed("/proc/self/stat"); |
| 427 | + return Long.parseLong(new String(statFile.readAllBytes()).trim().split(" ")[0]); |
425 | 428 | }
|
426 | 429 |
|
427 | 430 | @Specialization
|
|
0 commit comments