1、通过ps命令的两种选项形式查看进程信息 [root@localhost ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 128164 6824 ? Ss 14:31 0:02 /usr/lib/systemd/systemd --switched-root root 2 0.0 0.0 0 0 ? S 14:31 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 14:31 0:02 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 14:31 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S 14:31 0:00 [kworker/u256:0] root 7 0.0 0.0 0 0 ? S 14:31 0:00 [migration/0]
[root@localhost ~]# ps -elf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 1 0 0 80 0 - 32041 ep_pol 14:31 ? 00:00:02 /usr/lib/systemd/systemd --swi 1 S root 2 0 0 80 0 - 0 kthrea 14:31 ? 00:00:00 [kthreadd] 1 S root 3 2 0 80 0 - 0 smpboo 14:31 ? 00:00:02 [ksoftirqd/0] 1 S root 5 2 0 60 -20 - 0 worker 14:31 ? 00:00:00 [kworker/0:0H] 1 S root 6 2 0 80 0 - 0 worker 14:31 ? 00:00:00 [kworker/u256:0] 1 S root 7 2 0 -40 - - 0 smpboo 14:31 ? 00:00:00 [migration/0] 2、通过top命令查看进程 [root@localhost ~]# top top - 20:23:35 up 5:52, 4 users, load average: 0.00, 0.01, 0.05 Tasks: 175 total, 1 running, 174 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 1867024 total, 676812 free, 665692 used, 524520 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 990180 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 128164 6824 4056 S 0.0 0.4 0:02.65 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:02.46 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 6 root 20 0 0 0 0 S 0.0 0.0 0:00.28 kworker/u256:0 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 3、通过pgrep命令查看sshd服务的进程号 [root@localhost ~]# pgrep -l sshd 1026 sshd 2917 sshd 5392 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 ^Z [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@localhost ~]# dd if=/dev/zero of=/root/file2 bs=1M count=8190 & [2] 6424 8、查看后台的任务列表 [root@localhost ~]# jobs [1]+ 已停止 dd if=/dev/zero of=/root/file bs=1M count=8190 [2]- 运行中 dd if=/dev/zero of=/root/file2 bs=1M count=8190 & 9、恢复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 & [2] 已停止 dd if=/dev/zero of=/root/file2 bs=1M count=8190 10、查询dd if=/dev/zero of=/root/file bs=1M count=8190 命令的进程并通过kill杀死 [root@localhost ~]# ps aux |grep dd root 6364 0.6 0.0 108984 1668 pts/2 T 20:29 0:04 dd if=/dev/zero of=/root/file bs=1M count=8190 [root@localhost ~]# kill -9 6364 11、设置一次性计划任务在18:00时关闭系统,并查看任务信息 [root@localhost ~]# at 18:00 at> shutdown -h now at> <EOT> job 2 at Sat Aug 10 18:00:00 2019 [root@localhost ~]# atq 2 Sat Aug 10 18:00:00 2019 a root
12、以root身份设置周期性计划任务 a) 每天晚上的24点时打包压缩 /etc/passwd /etc/shadow /etc/group /etc/gshadow 为 file.tar.gz 00 00 * * * tar zcvf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow b) 每周一的每隔五分钟列出磁盘使用状况 */5 * * * 1 fdisk -l c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间 30 8 * * * ntpdate pool.ntp.org 13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容 [root@localhost ~]# crontab -l -u root 00 00 * * * tar zcvf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow */5 * * * 1 fdisk -l 30 8 * * * ntpdate pool.ntp.org
[root@localhost ~]# cat /var/spool/cron/root 00 00 * * * tar zcvf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow */5 * * * 1 fdisk -l 30 8 * * * ntpdate pool.ntp.org