Is it possible to create an instance of Process class if I have pid of process which already running? And put this Process in Map processMap. And then be able to stop Processes or check IsAlive
Asked
Active
Viewed 103 times
0
-
and do what with it? Are you simply looking to find if that process has completed, or are you trying to connect to its streams, or ... – Andy Turner Feb 05 '20 at 08:51
-
@Andy and put this Process in Map
processMap. And then be able to stop Processes or check IsAlive – SorryForAsking Feb 05 '20 at 08:53
1 Answers
1
This isn't what Process
is for:
Process provides control of native processes started by ProcessBuilder.start and Runtime.exec.
That's not to say you can't control already-running processes from Java; it's just that Process
isn't the thing you should use to do it.
You can make your own class to do what you say you need, e.g:
interface ExternalProcess {
boolean isRunning();
void kill();
}
with implementations of the methods such as:

Andy Turner
- 137,514
- 11
- 162
- 243