当前位置:网站首页>[轻松学会shell编程]-5、计划任务
[轻松学会shell编程]-5、计划任务
2022-06-25 06:33:00 【FanMY_71】
1、计划任务
创建和管理在指定时间自动执行的任务
注意事项:要使任务计划在指定时间自动运行,计划任务的服务必须使启动的。
1.1、计划任务的分类
- 使用at命令调用atd进程设置在某个特定的时间,执行一次任务
- 使用crontab命令调用crond进程,设置按固定的周期(如每天,每周等)重复执行预先计划好的任务
crond进行是一直在运行的
[[email protected] ~]# ps aux|grep crond
root 693 0.0 0.0 126384 1624 ? Ss 13:16 0:00 /usr/sbin/crond -n
1.2、守护进程(Daemon)
定义:一直在内存里运行的进程,直到我们人为的停止它的运行,不然它是一直在内存中运行的。因为一直在内存里运行,所以我们的用户可以随时去访问。
我们若是用"ps aux"命令来查看,会看到很多带末尾带"d"的进程,那么这些进程就是守护进程。
1.2.1、进程的五态

上面的守护状态,是一直在"运行"、"阻塞"、"就绪"这三种状态中循环往复的。
1.3、at命令
定义:在指定的日期、时间点自动执行预先设置的一些命令操作,属于一次性计划任务
- 系统服务的名称:/etc/init.d/atd
- 设置格式 :at [HH:MM] [yyyy-mm-dd]

设置任务的时候,首先我们要先启动std进程,不然就不会定时的去执行计划任务。
[[email protected] rough_book]# service atd start
Redirecting to /bin/systemctl start atd.service
[[email protected] rough_book]# ls
[[email protected] rough_book]# at 21:58
at> mkdir fan$RANDOM
at> <EOT> # 使用ctrl+d,提交计划任务
job 1 at Thu Jun 23 21:58:00 2022
# 查看当前的计划任务列表
[[email protected] rough_book]# at -l
1 Thu Jun 23 21:58:00 2022 a root
# 等到了21:58,你可以看到有一个新建的文件。
[[email protected] rough_book]# ls
fan28985
# 删除计划任务编号为2的任务,atrm等价于at -d
[[email protected] rough_book]# atrm 2
1.3.1、计划任务的存储地方
存放任务的地方:/var/spool/at
[[email protected] rough_book]# at -l
4 Thu Jun 23 22:03:00 2022 a root
[[email protected] rough_book]# ls /var/spool/at
a0000401a5240b spool
# 原理就是atd这个进程到了时间,就会去执行/var/spool/at中对应a开头的文件。。因为linux里面一切接文件。任务一旦执行完毕,文件就会消失。1.3.2、batch
batch是和at差不多的计划任务命 令。batch会自动在系统负载不高的时候运行。那么什么时候不忙呢?就是平均负载小于0.8
[[email protected] rough_book]# top
top - 22:10:28 up 8:54, 5 users, load average: 0.00, 0.01, 0.05
# 查看系统开机多久了,以及系统的平均负载
[[email protected] rough_book]# uptime
22:10:51 up 8:54, 5 users, load average: 0.00, 0.01, 0.05
# load average后面的这三个数字表示:在1、5、15分钟的平均负载
# 这两个命令都可以查看系统的负载平均负载:是一段时间内(1、5、15分钟)可运行的或不可中断的进程的平均数量。可以理解为就绪队和运行、阻塞里的进程的数量。这个值的多少跟CPU的核有关系。
man uptime:查看uptime手册可以看到以下关于系统平均负载的内容
System load averages is the average number of processes that are either in a runnable or uninter‐ ruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPUsystem it means it was idle 75% of the time.
系统平均负载是指处于可运行状态或不可中断状态的过程的平均数量。 处于可运行状态的进程正在使用CPU,或者正在等待使用CPU。 处于不可中断状态的进程正在等待一些I/O访问,例如等待磁盘。 取三个时间间隔的平均值。 平均负载不是按照系统中CPU的数量进行规范化的,所以平均负载为1意味着单个CPU系统一直处于加载状态,而CPU数量为4个CPU系统,它意味着75%的时间是空闲的。
2、crond进程
crond进程是每隔1分钟就去检查用户的计划任务;crond默认安装的且开机会自动运行。详细的可以查看下面这个博客。
[linux]三、计划任务(crontab、黑客怎么用计划任务获取我们的东西以及怎么排查、前台和后台、anacron服务)_FanMY_71的博客-CSDN博客
边栏推荐
- Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution
- Global and Chinese kaolin market operation scale and investment development proposal report 2022
- Research Report on marketing channel analysis and competitive strategy of China's polycarbonate industry 2022
- Research Report on investment share and application prospect of 1,3-propanediol (PDO) industry in the world and China 2022
- アルマ / 炼金妹
- The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
- ASP. Net core - Safety of asynclocal in asp NET Core
- Why study discrete mathematics
- Global and China financial guarantee marketing strategy and channel dynamic construction report 2022
- Cs8683 (120W mono class D power amplifier IC)
猜你喜欢

JSON. toJSONString(object, SerializerFeature.WriteMapNullValue); Second parameter action

The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse

Zero foundation wants to learn web security, how to get started?

ACWING/2004. 错字

JS dynamic table creation

VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.

@Detailed explanation of valid annotation usage

After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling

Acwing / 2004. Mauvaise écriture

百度地图——入门教程
随机推荐
北京网上开股票账户安全吗?
原子Alpha开发板--SD卡和emmc烧录工具
How do I check swift if two arrays contain the same elements, regardless of the order in which they appear?
Navicat防止新建查询误删
Self adjustment process of MySQL index tree when adding data
Analysis report on demand scale and Supply Prospect of global and Chinese thermal insulation materials market during the 14th Five Year Plan period 2022-2028
@The difference between notempty, @notnull and @notblank
Is the number of indexes in a table the more the better?
Analysis report on production and sales demand and sales prospect of global and Chinese phosphating solution Market 2022-2028
Exercise: completion
Rational investment and internationalism
Research Report on brand strategic management and marketing trends in the global and Chinese preserved fruit market 2022
Global and Chinese gallium nitride (GAN) market output value scale forecast and application prospect analysis report 2022
delphi-UUID
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
[Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security
Unity获取资源路径
Cs5092 5V USB input boost two section lithium battery charging management IC, SOT23-6 miniature package
JS to determine whether an element exists in the array (four methods)
fastadmin 联级清空数据