• chapter10--进程和计划任务管理


    1、通过ps命令的两种选项形式查看进程信息
    [root@localhost ~]# ps aux   //以简单列表的形式显示进程信息
    [root@localhost ~]# ps -elf   //以长格式显示进程信息,内容更丰富
     
    2、通过top命令查看进程
    [root@localhost ~]# top -b  
     
    3、通过pgrep命令查看sshd服务的进程号
    [root@localhost ~]# pgrep -l "sshd"    // -l  显示进程名
    1415 sshd
    2931 sshd
     
    4、查看系统进程树
    [root@localhost ~]# pstree
     
    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     //在前台执行,ctrl+Z调入后台并停止执行
    ^Z
    [1]+  已停止               dd if=/dev/zero of=/root/file bs=1M count=8190
    [root@localhost ~]# jobs -l      //查看后台的任务列表
    [1]+  4338 停止                  dd if=/dev/zero of=/root/file bs=1M count=8190
     
    7、使dd if=/dev/zero of=/root/file2 bs=1M count=1024 命令操作在后台运行
    [root@localhost ~]# bg 1      //将后台暂停的命令调入后台运行
    [1]+ dd if=/dev/zero of=/root/file bs=1M count=8190 &
     
    8、查看后台的任务列表
    [root@localhost ~]# jobs -l
    [1]+  4338 运行中               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 ~]# dd if=/dev/zero of=/root/file bs=1M count=8190
    ^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
    [root@localhost ~]# bg 1
    [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 &
     
    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
    p^H^Z
    [1]+  已停止               dd if=/dev/zero of=/root/file bs=1M count=8190
    [root@localhost ~]# jobs -l
    [1]+  4434 停止                  dd if=/dev/zero of=/root/file bs=1M count=8190
    [root@localhost ~]# bg 1
    [1]+ dd if=/dev/zero of=/root/file bs=1M count=8190 &
    [root@localhost ~]# kill  -9 4434    //强制杀死进程
    [root@localhost ~]# jobs -l
    [1]+  4434 已终止               dd if=/dev/zero of=/root/file bs=1M count=8190
     
    11、设置一次性计划任务在18:00时关闭系统,并查看任务信息
    [root@localhost ~]# date
    2019年 08月 08日 星期四 11:22:31 CST
    [root@localhost ~]# at 18:00
    at> shutdown -h now
    at> <EOT>
    job 1 at Thu Aug  8 18:00:00 2019
    [root@localhost ~]# atq
    1 Thu Aug  8 18:00:00 2019 a root
     
    12、以root身份设置周期性计划任务
    a) 每天晚上的24点时打包压缩 /etc/passwd /etc/shadow /etc/group /etc/gshadow 为 file.tar.gz
    [root@localhost ~]# crontab -e -u root     //进入编辑
    [root@localhost ~]# crontab -l    //查看计划任务
    0 0 * * * tar -czf file.tar.gz /etc/passwd
    0 0 * * * tar -czf file.tar.gz /etc/shadow
    0 0 * * * tar -czf file.tar.gz /etc/group
    0 0 * * * tar -czf file.tar.gz /etc/gshadow
    b) 每周一的每隔五分钟列出磁盘使用状况
    [root@localhost ~]# crontab -e -u root
    */5     0 * * * df -Th
    c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间
    [root@localhost ~]# crontab -e -u root
    30 8 * * * ntpdate pool.ntp.org
     
    13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容
    [root@localhost ~]# crontab -l -u root
    0 0 * * * tar -czf file.tar.gz /etc/passwd
    0 0 * * * tar -czf file.tar.gz /etc/shadow
    0 0 * * * tar -czf file.tar.gz /etc/group
    0 0 * * * tar -czf file.tar.gz /etc/gshadow
    */5     0 * * * df -Th
    30 8 * * * ntpdate pool.ntp.org
     
    [root@localhost ~]# cat /var/spool/cron/root
    0 0 * * * tar -czf file.tar.gz /etc/passwd
    0 0 * * * tar -czf file.tar.gz /etc/shadow
    0 0 * * * tar -czf file.tar.gz /etc/group
    0 0 * * * tar -czf file.tar.gz /etc/gshadow
    */5     0 * * 1 df -Th
    30 8 * * * ntpdate pool.ntp.org
  • 相关阅读:
    poj1330 Nearest Common Ancestors
    poj3237 Tree
    spoj2798 QTREE3 Query on a tree again!
    spoj913 QTREE2 Query on a treeⅡ
    自动类型转换
    js "+"连接符号
    js parseFloat
    js字符串与数字的运算
    js prompt
    js数组排序
  • 原文地址:https://www.cnblogs.com/qiyueqi/p/11342598.html
Copyright © 2020-2023  润新知