문제

I'm looking for a solution capable of doing this on Java:

  • Spawn a process.
  • Suspend it (like kill -STOP does in Linux).
  • Continue a suspended process (like kill -CONT in Linux).
  • Read/Write their standard input/output pipes at runtime.
  • Working on (at least) Linux and Windows.

As far as I know, the Java standar only implements first and fourth, but not the second neither the third.

What could I do?

도움이 되었습니까?

해결책

There is no way of doing "directly" from Java.

You will need to do something specific for Windows / Linux, in each case executing an external program, or invoking native code.

On Linux, you can use kill as you suggest.

On Windows, you can call SuspendThread(), or maybe you can launch the SysInternals tool 'PsSuspend'. There is some information that may help you here:

How to pause / resume any external process under Windows?

How to suspend/resume a process in Windows?

If you wish to invoke native code from Java, JNIWrapper may help you.

Also, if you need the PIDs of the spawned processes, then you may need to launch them via native code also, as Java will not give you their PIDs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top