I would like to start a java process...and then check if its still running after 10 seconds from a bash script.
Is there an easy way to do this?
|
I would like to start a java process...and then check if its still running after 10 seconds from a bash script. Is there an easy way to do this? |
|||
|
|
|
You can do this a bit better by using
|
|||
|
|
|
Thanks for your question. You might want to take a look at the following sample script and see if this is what you require:
The ‘if’ statement below checks to see if the process is running with the help of the ‘ps’ command. In the if statement, "ps aux" lists the current running processes. The next section finds out the your process, then we eliminate the grep process from the obtained list of your processes and finally, count the number of instances. If that result is greater than zero, your process is running, else it isn't. Hope this helps... |
|||
|
|
|
Save the Process ID of the java process you created, (invoke it immediately). PID=$(pgrep -n java | head -n 1) Later use process search to find using the PID
at this point if |
|||
|
|
|
well, make a file called something.sh, replace program with the name of your program:
If the output is empty then it has stopped working. Launch it with sh something.sh. |
|||
|
|