質問

I have java process which uses process builder and calls a perl script. The perl script internally calls a binary in background and i have its process id in that perl script.Now i can return this process id back to java.

So now I have the process id in java. I just want to monitor that process in java whether its running or whether its not running. How can i do this monitoring inside java. Probably i need java threads but i am a bit new to java.So could anybody please suggest some directions?

役に立ちましたか?

解決

Perhaps the easiest way is to check the /proc filesystem

If process 1234 exists, there's a corresponding file entry /proc/1234.

他のヒント

Java monitors only the Process created with ProcessBuilder class or Runtime.exec() method.

You could execute a native command like ps aux | grep <pid> and get the output of that command from within java using a class like ProcessBuilder. Interpreting the output will tell you if the process is still running.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top