Linux cron 源碼剖析

背景及 busybox 介紹

流程圖

main.png

1-2.png

1-3.png

數據結構

typedef struct CronFile {
    struct CronFile *cf_next;
    struct CronLine *cf_lines;
    char *cf_username;
    smallint cf_wants_starting;     /* bool: one or more jobs ready */
    smallint cf_has_running;        /* bool: one or more jobs running */
    smallint cf_deleted;            /* marked for deletion (but still has running jobs) */
} CronFile;

typedef struct CronLine {
    struct CronLine *cl_next;
    char *cl_cmd;                   /* shell command */
    pid_t cl_pid;                   /* >0:running, <0:needs to be started in this minute, 0:dormant */
#define START_ME_REBOOT -2
#define START_ME_NORMAL -1
#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
    int cl_empty_mail_size;         /* size of mail header only, 0 if no mailfile */
    char *cl_mailto;                /* whom to mail results, may be NULL */
#endif
    char *cl_shell;
    /* ordered by size, not in natural order. makes code smaller: */
    char cl_Dow[7];                 /* 0-6, beginning sunday */
    char cl_Mons[12];               /* 0-11 */
    char cl_Hrs[24];                /* 0-23 */
    char cl_Days[32];               /* 1-31 */
    char cl_Mins[60];               /* 0-59 */
} CronLine;

cron 使用方法

分析

代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章