SorryForAsking
SorryForAsking

Reputation: 373

Is it possible to create an instance of Process class if I have pid? Java

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

Upvotes: 0

Views: 123

Answers (1)

Andy Turner
Andy Turner

Reputation: 140318

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:

Upvotes: 1

Related Questions