Linux 10---进程和计划任务管理

1、通过ps命令的两种选项形式查看进程信息

[root@localhost ~]# ps aux

[root@localhost ~]# ps -elf

2、通过top命令查看进程

[root@localhost ~]# top -d 5
top - 12:37:18 up 38 min , (启动时长)4 users, (用户个数)load average:(系统负载平均值) 0.02,(1分钟) 0.02(5分钟), 0.05(15分钟)
Tasks: 180 total, 1 running, 179 sleeping, 0 stopped, 0 zombie             注:第二行为进程信息
%Cpu(s): 5.6 us用户, 5.6 sy系统, 0.0 ni, 88.9 id定闲, 0.0 wa, 0.0 hi硬件, 0.0 si软件, 0.0 st虚拟化
KiB Mem : 2031888 total, 98116 free, 690880 used, 1242892 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1103784 avail Mem     注:虚拟内存

3、通过pgrep命令查看sshd服务的进程号

[root@localhost ~]# pgrep -l sshd
1059 sshd
2737 sshd
56182 sshd

4、查看系统进程树

[root@localhost ~]# pstree -aup       注:-a 显示完整信息 ;-u 列出对应用户名 ;-p 列出对应PID号

5、使dd if=/dev/zero of=/root/file bs=1M count=8190 命令操作在前台运行

[root@localhost ~]# dd if=/dev/zero of=/root/file bs=1M count=8190

6、将第5题命令操作调入到后台并暂停

[root@localhost ~]# dd if=/dev/zero of=/root/file bs=1M count=8190
^Z                                          Ctrl+Z
[1]+ 已停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[root@localhost ~]# jobs
[1]+ 已停止 dd if=/dev/zero of=/root/file bs=1M count=8190

7、使dd if=/dev/zero of=/root/file2 bs=1M count=1024 命令操作在后台运行

[root@bogon ~]# dd if=/dev/zero of=/root/file2 bs=1M count=1024 &

8、查看后台的任务列表

[root@localhost ~]# dd if=/dev/zero of=/root/file bs=1M count=8190 &
[3] 56574
[root@localhost ~]# jobs -l
[2]- 56573 运行中 dd if=/dev/zero of=/root/file bs=1M count=8190 &
[3]+ 56574 运行中 dd if=/dev/zero of=/root/file bs=1M count=8190 &

9、恢复dd if=/dev/zero of=/root/file bs=1M count=8190 让其在后台继续运行

[root@localhost ~]# bg
[1]+ dd if=/dev/zero of=/root/file bs=1M count=8190 &

10、查询dd if=/dev/zero of=/root/file bs=1M count=8190 命令的进程并通过kill杀死

[root@localhost ~]# dd if=/dev/zero of=/root/file bs=1M count=8190 &
[1] 56604
[root@localhost ~]# kill -9 56604
[root@localhost ~]# bg
-bash: bg: 任务已经终止
[1]+ 已杀死 dd if=/dev/zero of=/root/file bs=1M count=8190

11、设置一次性计划任务在18:00时关闭系统,并查看任务信息

[root@localhost ~]# at 18:00
at> init 0
at> <EOT>       注: Ctrl+d
job 1 at Sat Aug 3 18:00:00 2019

12、以root身份设置周期性计划任务
a) 每天晚上的24点时打包压缩 /etc/passwd /etc/shadow /etc/group /etc/gshadow 为 file.tar.gz

b) 每周一的每隔五分钟列出磁盘使用状况

c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间

[root@localhost ~]# crontab -e   

vim /var/spool/cron/root(用户名)

0  0 * * * tar file.tar.gz /etc/passwd 

0 0 * * * tar file.tar.gz /etc/shadow
0 0 * * * tar file.tar.gz /etc/group
0 0 * * * tar file.tar.gz /etc/gshadow
*/5 * * * */1 df -Th
30 8 * * * ntpdate pool.ntp.org

[root@localhost ~]# systemctl restart crond

13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容

[root@localhost ~]# cat /var/spool/cron/root
0 0 * * * tar file.tar.gz /etc/passwd
0 0 * * * tar file.tar.gz /etc/shadow
0 0 * * * tar file.tar.gz /etc/group
0 0 * * * tar file.tar.gz /etc/gshadow
*/5 * * * */1 df -Th
30 8 * * * ntpdate pool.ntp.org

[root@localhost ~]# crontab -l -u root
0 0 * * * tar file.tar.gz /etc/passwd
0 0 * * * tar file.tar.gz /etc/shadow
0 0 * * * tar file.tar.gz /etc/group
0 0 * * * tar file.tar.gz /etc/gshadow
*/5 * * * */1 df -Th
30 8 * * * ntpdate pool.ntp.org

原文地址:https://www.cnblogs.com/wangjia120/p/11325204.html