0

I've got a number of php processes that I'm running in the background, with monit as the manager for them. My current config for monit looks like:

check process myprocess1
      matching "process1.php"
      start program = "/usr/bin/php /path/to/process1.php > /var/log/process1.log"
      stop program = "/usr/bin/pkill /path/to/process1.php"

(Again, remember that there are several processes like this one.) This is working for starting processes, but not for stopping them -- the stop attempt fails with a monat "failed to stop" message. My current diagnosis of this situation is that it's failing because pkill isn't finding the process: doing the analogous pgrep /path/to/process1.php fails to find anything. ps ax shows, among other things:

5307 ? S 0:00 /usr/bin/php /path/to/process1.php

Meanwhile, pgrep php succeeds in finding pids of all the php processes, but I only want to kill one of them.

So: Is there a way to get what I want here? I'm not wedded to using pkill, but it seems to be well thought-of...

1 Answer 1

1

Check out pgrep/pkill's f flag for full.

-f, --full use full process name to match

I'm not 100% sure that this will help your, but if you already have process1.php this will help you kill the appropriate program.

Example: I run "php rob/conmon.php" and pgrep -f 'php rob/conmon.php' returns the proper PID and pkill -f 'php rob/conmon.php' equivalently kills the PID.

Hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .