Linux's Crond (b)

Due to recent work uses crond, before crond not quite understand, only know that ye use, but this needs to be considered a lot of cases, it is also in-depth understanding of what crond, following on the following issues to talk about crond.

  1. crond specified in the job, if this is not executed, the next execution cycle came around again, this time what will happen?

    A: The job is not finished, then execute the next execution cycle went to, job will be repeated. Can be viewed with the ps command, the following are the results I see.

    [root@localhost etc]# ps -ef | grep Test
    root      48460  73018  0 18:34 pts/0    00:00:00 grep --color=auto Test
    root      98880  98878  0 18:06 ?        00:00:00 php Test.php
    root     101631 101629  0 18:07 ?        00:00:00 php Test.php
    root     104427 104425  0 18:08 ?        00:00:00 php Test.php
  2. How to avoid duplicate crond the job enforce it?

    Can refer to crontab does not solve the execution cycle End Repeat this blog article talked about the three methods (use a mutex), I had the solution is to set the mark $ bool whether a job that can be performed in Reids, the pseudo code show as below:

    //Test.php 文件的主要内容
    $redis = new Redis();
    $keyExist = $redis->exists('job_can_start');
    if (!$keyExist) {
        $redis->set('job_can_start',1);
        $canExcute = 1;
    } else {
        $canExcute = $redis->get('job_can_start');
    }
    if ($canExcute){
        $redis->set('job_can_start', 0);
        //下面写具体的job
        …………
    
    
       $redis->set('job_can_start', 1);
    }
  3. The service crond off, it will affect job executing it?

    As far as I know the test, shut down the process crond service will not affect the job being performed, the process will exit automatically when the job after the implementation of job execution.

    Testing process is as follows:

    1. Writing a job, and then perform the task using the Task Scheduler (execution time is much shorter than the period of execution of tasks you want to pay attention to the task to be set, so the effect is obvious, please refer to the specific use crond how https://www.cnblogs.com/ zhuchenglin / the p-/ 8758444.html ).
    2. This time using the command ps look at the number of script execution process, which is expected after several cycles, and then look at the number of execution of the script process, then the number of previously viewed ratio should be increased significantly
    3. The crond service turned off, and immediately see the number of processes, the number of process at this time should be little change, and then view the number of processes after a few cycles should be reduced.
  4. crond operating principle

    In fact, a few questions if you understand the above principle run Linux cron job, it should be very easy. Here I recommend a blog run principle Cron , which talked about the workflow crond, the junior partner interest can be studied carefully study.

For reprint, please indicate the source: https://www.cnblogs.com/zhuchenglin/p/11514777.html

Guess you like

Origin www.cnblogs.com/zhuchenglin/p/11514777.html