Scheduling Processes

  • All the processes are started when systems boots or when a command is run.

  • Processes/commands can be scheduled to be executed at a specific time on a specific date by using the cron daemon.

Commands

crontab

  • crontab - maintain crontab files for individual users

    • A crontab file contains instructions for the cron daemon

    • crond - daemon to execute scheduled commands

    • Each user can define their own crontab and the commands are executed under the user who owns that particular crontab

# Systems level crontabs
less /etc/crontab
    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.

    SHELL=/bin/sh
    # You can also override PATH, but by default, newer versions inherit it from the environment
    #PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # *  *  *  *  * user-name command to be executed
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    #

# anacron runs processes on a set schedule (hourly, daily, weekly, monthly)

ls -lah /etc/cron.daily/
    total 56K
    drwxr-xr-x   2 root root 4,0K ott  5 09:09 .
    drwxr-xr-x 135 root root  12K nov  3 21:47 ..
    -rwxr-xr-x   1 root root  311 lug 16  2019 0anacron
    -rwxr-xr-x   1 root root  376 dic  4  2019 apport
    -rwxr-xr-x   1 root root 1,5K lug 28 09:26 apt-compat
    -rwxr-xr-x   1 root root  355 dic 29  2017 bsdmainutils.dpkg-remove
    -rwxr-xr-x   1 root root  384 nov 19  2019 cracklib-runtime
    -rwxr-xr-x   1 root root  123 dic  5  2021 dpkg
    -rwxr-xr-x   1 root root  377 gen 21  2019 logrotate
    -rwxr-xr-x   1 root root 1,3K mar 17  2022 man-db
    -rw-r--r--   1 root root  102 feb 13  2020 .placeholder
    -rwxr-xr-x   1 root root  652 dic  7  2020 plocate
# Every script is own by root, since they are associated to system-wide processes

πŸ“Œ Check the crontab.guru editor for cron schedule expressions.

Boot Process

  • /etc/init.d - contains start/stop scripts for various services, while booting and shutting down the system

    • init (short for initialization) is the program that spawns all other processes. It runs as a daemon and typically has PID 1.

    • The applications that are started by init are located in the /etc/rc.d folder. Within this directory there is a separate folder for each run level, eg rc0.d, rc1.d, and so on.


Last updated

Was this helpful?