I have some runnable-jar files. I want to run them at regular intervals and also kill those processes after some time. I am a newbie when it comes to Ubuntu or linux in general. Can anybody suggest me the best practice to achieve it?
|
Use something like
in a file, make it executable (chmod +x ) and run it using
This will start the jar-file and kill it after some time. There are several ways to excecute the command at regular intervals. You could use
This will run the command 100 times, you could stop the execution simply by pressing ctrl-c. |
|||||||||||||
|
|
The best way would be to create a shell script that runs the the executable, retrieves the PID of the process then kill it after a certain amount of time. You can then add this as a job in your crontab to launch it at regular intervals. |
|||
|
|
|
For killing a process using kill command, we have to keep track of PID of the process to be killed. So, we have used pkill -f to kill the process. Now, I only have to remember the name of process and do not want to track the PID. The code for starting process remains the same. Hope it helps for somebody who comes here searching for the answer. |
|||
|
|