If I put in cron two tasks for execution at the same time, then how will they be executed (and executed): in parallel or alternately (the second will be executed after the first)?

  • one
    will be parallel - Mike
  • @Mike, i.e., if I want to execute them sequentially, then I need to jot down a simple script and put it to execution? Right? Or are there other options? - user212277
  • @Mike And another question then ... If the task set in cron (for example, every minute) does not have time to complete, and the deadline for re-staging has already come, will its second instance start, or will cron still wait for the first one to finish? - user212277
  • one
    Well, if you don’t have a lot of parameters, you can write several tasks directly to cron задача1 параметры && задача2 параметры . True in this case, task 2 will be executed after the successful implementation of the first. You can try, in principle, through a semicolon in one line, it seems to me that it should work that way. If the task does not complete the cron will run it a second time. Therefore, the task itself must control that there are no copies of it now (parimer is again a script that puts its PID in / var / run and checks if there is a file and a task with such a PID at startup) -
  • @Mike Thank you. Make out the answer, if not laziness :) - user212277

1 answer 1

If tasks are described in crontab in different lines, they will be executed independently of each other, including in parallel, if the time coincides.

If you want the two tasks to be performed strictly one after the other, you can write them in one line, separated by a semicolon:

 01 12 * * * mike task1 parameters; task2 parameters; ... 

In addition, if by the time of its next start the previous instance of the task has not yet completed, the cron will not check anything and will launch the second copy. Tracking a parallel launch and preventing it remains on the conscience of the task itself.