Calculate when jobs scheduled with different frequencies will align

27 Views Asked by At

Suppose I have the following "tasks" scheduled to "run" at the following frequecies:

$t_1$ --> Every $3$ hours, on minute $0$

$t_2$ --> Every $5$ hours, on minute $0$

$t_3$ --> Every $2$ hours, on minute $0$

$t_4$ --> Every $5$ minutes

How can I calculate when these tasks will run at the same time?

For instance, how can I calculate:

  1. How long it takes for $t_1$ and $t_2$ to run on the same minute?
  2. How long does it take for $t_1$, $t_3$, $t_4$ to run on the same minute?
  3. How long does it take for all of them to run on the same minute?

My approach

For the first comparison, I would think that by looking when $$3 \times n_\text{periods} \mod 12$$ equals $$5 \times n_\text{periods} \mod 12$$

Is this the correct path? And how would I find a formula that tells me how much I need to wait for them to align?

My idea is that I would have $$180\times n \equiv 300\times n \equiv 120 \times n \equiv 5 \times n \qquad \mod 12$$

which I think is equivalent to

$$0\times n \equiv 0\times n \equiv 0 \times n \equiv 5 \times n \qquad \mod 12$$