CENTOS7 in process and task management plans

linux in the process of planning and task management


1. The  relationship between the programs and processes

Program : executable code and data stored in a hard disk medium, optical disk, etc.; static code stored

Process : The CPU program code running and memory; dynamic code execution; parent and the child: Every process can create one or more processes

Basic Commands

1 ): PS command ( Processes statistc ): View static process statistics

-aux PS : showing process information in the form of a simple list.

a view option indicates that all process information

u option indicates that the user information display process belongs

x option indicates that information other than the default message 


image.png


ps -elf: displaying a long format process information system and contains richer content.

e parameter represents the entire process

f parameter representing the whole format

parameter represents the format length l

image.png

  1. PID: ID of running processes;

  2. TTY: Location command to run

  3. TIME: running the command occupied by CPU processing time

  4. CMD: The command process running




2 ): Top commands: display a full-screen interactive ranking process interface, by default three seconds to refresh, the default sort order cup occupancy rate.

Common options: -d: Specifies the refresh time in seconds

                  -b: a batch processing mode, typically used in conjunction with -n

                  Specifies the number of times through the bad display: -n

                  -u: Specifies the user name

                  -p: to develop process ID

image.png

PID: Process ID

USER: User running processes

PR:系统默认的优先级,PR总是比NI大20

NI:用户可以修改的优先级。范围从-20~19 ,数字越小值越大。当进程已经运行时,可以使用 renice 命令修改其优先级:renice  -n   -20  PID   。当进程没运行时,可以使用 nice -n 20  httpd  开启进程的时候指定优先级

VIRT:虚拟内存

RES: 当前进程使用的内存

SHR:共享内存

S : 状态 S(sleep) 或者 R(running)

%CPU:进程所占CPU的比重

%MEM: 进程所占内存的比重

Time : 进程运行的时间

COMMAND: 进程的指令


S状态的分类:

S(大写):可中断休眠进程

D:不可中断休眠进程

s:父进程

<:优先级高

R:正在运行的进程

l:多线性进程

N:优先级低

Z:僵尸进程

+:前台进程



注意:cpu占用率过高时,不应直接用top查看,可以将信息存入一个文件内查看,以免cup占用率过高导致崩溃。



3):pgrep命令:根据特定条件查询进程 PID 信息

常用选项:

-l:显示进程名

-U:指定特定用户

-t:指定终端

image.png





4):pstree命令:以树形结构列出进程信息

常用选项:

-a:显示完整信息

-u:列出对应的用户名

-p:列出对应的PID号

格式pstree –aup pstree –ap 用户

image.png

 

2.进程的启动方式

手工启动

前台启动foreground,前台):用户输入命令,直接执行程序

后台启动background,后台):在命令行尾加入“&”符号

[root@localhost ~]# cp /dev/cdrom mycd.iso &

[1] 28454 (输出信息中包括后台任务序号、PID号)

 调度启动

使用 at 命令,设置一次性计划任务;

使用 crontab 命令,设置周期性计划任务

 

3.进程的前后台调度

1):Ctrl+Z 组合键:将当前进程挂起,即调入后台并停止执行

image.png

2):jobs 命令:查看处于后台的任务列表 ;格式:jobs -l

image.png

3):fg 命令:将后台进程恢复到前台运行,可指定任务序号

image.png

4):bg命令:将后台挂起的进程继续在后台执行 

image.png

 

4.终止进程

Ctrl+C 组合键:中断正在执行的命令

 killkillall 命令

kill用于终止指定PID号的进程

image.png

killall用于终止指定名称的所有进程

image.png

-9 选项用于强制终止

   pkill命令:根据特定条件终止相应的进程

image.png

image.png

常用命令选项

 -U:根据进程所属的用户名终止相应进程;

-t:根据进程所在的终端终止相应进程

 

5.计划任务管理

 1):at命令:一次性计划任务,前提是对应的系统服务atd必须已经运行;计划任务执行任务的时间必须安排在当前系统时间后。

服务脚本名称:/etc/init.d/atd;格式:at  [HH:MM]  [yyyy-mm-dd]

使用at命令,设置一次性任务计划

设置格式:at 小时:分钟    年-月-日    (设置当天的任务不可加日期)

image.png

基本操作 :

ctrl+D 保存退出

atq 查询现有的一次性计划

image.png

 atrm [任务序号] 删除第几项任务

image.png




2):crontab命令:按照预先设置的时间周期(分钟、小时、天……)重复执行用户指定的命令操作;属于周期性计划任务;服务脚本名称:/etc/init.d/crond

QQ picture 20190825140205.png

主要设置文件

全局配置文件,位于文件:/etc/crontab

image.png

系统默认的设置,位于目录:/etc/cron.*/

用户定义的设置,位于文件:/var/spool/cron/用户名

3):管理cron计划任务

编辑计划任务crontab  -e  [-u  用户名]

image.png

image.png

查看计划任务crontab  -I  [-u  用户名

image.png

删除计划任务crontab  -r  [-u  用户名]    (删除时会将所有计划性任务删除,如果要删除其中一条任务,需要用crontab -e 进入配置文件,用dd将要删除的任务删除即可)

image.png

注意:root用户可以管理指定用户的计划任务;普通用户只能管理自己的计划任务


 

 

6. 时间数值的特殊表示方法

*          表示该范围内的任意时间

,       表示间隔的多个不连续时间点

-           表示一个连续的时间范围

/           指定间隔的时间频率

举个例子

0  17  *  *  1-5          周一到周五每天17:00

308 * * 1,3,5       every Monday, Wednesday and Friday 8 Dian 30 Fen

08-18 / 2 * * * 8 am to 18 each between points 2 hours

* 0 * / 3 * *            every 3 days


Guess you like

Origin blog.51cto.com/14469918/2432396