I've got the following shell command that checks to see if a particular process is running:

pgrep -x com.package.name

It either returns a process ID if the process is running, or it returns empty if it's not. How can I pop this into a tasker profile that checks every few seconds and runs a task when it sees that the result is empty?

The ultimate goal here is to keep near 100% uptime on a process that has a tendency to crash multiple times a day.

1 Answer 1


I see two ways to do what you want.

Run a time based profile and set it to repeat after every n minutes. Then follow your logical actions in the task of what to do when it crashes.

The other option (since the former doesn't give control on seconds but minutes and hours) is to execute the task manually or at some point automatically (say at 10:00 AM) but make an infinitely looping task.

For example, consider the following actions:

Note: Anything with and between <> has to be replaced with your custom values.

  1. Code → Run Shell

    • Command: <YOUR_COMMAND>
    • Store Output In: %Grep
  2. Create this action based on what to do when the above command returns nothing i.e. when the process is not running.

    When doing so, set an 'If' condition under that action. E.g. under the action App → Launch App, the If condition would be %Grep Isn't Set.

    Note that I'm not talking about using a separate If action.

  3. Add a wait of the amount of seconds/minutes/hours you want using Task → Wait
  4. Now is the time to make an infinite loop. Use the action Task → Goto

    • Type: Action Number
    • Number: 1

All we've done here is to execute a command then execute an action if only the first command didn't yield anything, then wait for sometime and then repeat the whole procedure.

At some point, you would want to get rid of that infinite loop. You can either consider disabling and re-enabling Tasker or make a stop action in another task using Task → Stop, and execute it manually.

You must log in to answer this question.

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