Skip to content
This repository was archived by the owner on Jan 5, 2020. It is now read-only.

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minicrontab

TODO:

  • module design

    ./minicrontab &

fork -> fork -> the running instance -> fork to create scheduler -> fork job 1,2..N

  • study process session

  • redirect input/output

  • how to handle user to modify configuration file

  • sleep interval

  • other detailed implementation

Time conversion algorithm:

  • The daemon process has start time
  • The schedule process has the now time
  • So the clockTime = startTime + ( nowTime - startTime ) * rate
  • We can use clockTime to choose which job should be executed now.

study the http://enterprise-storage-os.googlecode.com/files/vixie-cron-4.1.tar.bz2

ISC cron tool code analysis

  1. fork processes to setup the correct process structure
  2. close input output stderr
  3. load the cron data to the cron database(read from files)
  4. calculate time and sleep
  5. check all the entry in database whether it should be run now
  6. add the to be running job into job queue
  7. run the job from job queue
  8. loop to step 3

data structure:

typedef struct _user {
    struct _user    *next, *prev;   /* links */
    char        *name;
    time_t      mtime;      /* last modtime of crontab */
    entry       *crontab;   /* this person's crontab */
} user;

typedef struct _cron_db {
    user        *head, *tail;   /* links */
    time_t      mtime;      /* last modtime on spooldir */
} cron_db;

typedef struct _entry {
    struct _entry   *next;
    struct passwd   *pwd;
    char        **envp;
    char        *cmd;
    char    min[60];
    char    hour[12];
    char    dom[31];    // day of month
    char    month[12];
    char    dow[7];     // day of week
    
    int     flags;
    #define	MIN_STAR	0x01
    #define	HR_STAR		0x02
    #define	DOM_STAR	0x04
    #define	DOW_STAR	0x08
    #define	WHEN_REBOOT	0x10
    #define	DONT_LOG	0x20
} entry;

typedef struct _job {
    struct _job *next;
    entry       *e;
    user        *u;
} job;
static job  *jhead = NULL, *jtail = NULL;

datagram

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages