문제

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