用crontab、crond在嵌入式系统中添加定时任务

用crontab、crond在嵌入式系统中添加定时任务

在嵌入式系统中,定时任务通过crond和cronttab两个系统命令来联合执行。

其中crond是定时任务的守护进程,系统开始时是没有开启的。crontab主要作用是管理用户的crontab files.

crontab - maintain cron-tab files for individual users
crond - daemon to execute scheduled commands

在编制busybox系统的时候,由于/var路径的容量实在是太小了,没有办法开始寻找其他的路径作为替代。

其中,crond和crontab默认是在 /var/spool/cron/crontabs/目录 执行和查找crontab任务的。

crontab -c /etc/crontabs/ /etc/crontabs/root
#change the default root_crontab_file to /etc/crontabs/root

crond -c /etc/crontabs/
#change crond directory

将上面这段代码加入到/etc/rc.d/rc.local的末尾。

其中root文件是其中针对root用户的cron-tab文件,其内容是:

0 */1 * * * hwclock -s
#每隔1个小时执行一次时钟 同步任务

另外,注意给root文件添加可执行权限。「chmod 777 /etc/crontabs/root」

crontab:是cron和table(表格)的组合。

crond:是cron和daemon(守护进程)的组合。

猜你喜欢

转载自blog.csdn.net/whereisdog/article/details/83585973