0

I have a process that I would like to identify, kill, and restart on a timed basis with a CRON job. I need to identify it where the executable string starts with "java" and contains "8091".

Once I identify the process, I want to run a kill -9 [that id]

And then I want to rerun the process by executing the identified executable string.

I am really stuck on the first piece of identification and then setting those two things as variables to use later in my process for the kill and for the restart. Could anyone give me a nudge on how to best accomplish this?

Thanks in advance.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Dave Shuck
  • 583
  • 1
  • 6
  • 19
  • 1
    `pgrep` is one way to start from, but you really should be looking into wrapping that into a shell script so you get the PID directly. – iBug Jun 24 '20 at 19:16
  • A service manager like systemd might even be better. But sure, with a wrapped script you'll be able to store the PID and take later. – iBug Jun 24 '20 at 19:17
  • See: [How to get process ID of background process?](https://stackoverflow.com/q/1908610/3776858) – Cyrus Jun 24 '20 at 19:18
  • You almost certainly should not use `-9` with `kill`. See also http://www.iki.fi/era/unix/award.html#kill – tripleee Jun 24 '20 at 19:25
  • 1
    @oguz Thanks for the feedback; switched to a better duplicate. – tripleee Jun 24 '20 at 19:35

0 Answers0