1、通过ps命令的两种选项形式查看进程信息
[root@localhost ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 128276 6892 ? Ss 13:56 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 13:56 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 13:56 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 13:56 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 13:56 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 13:56 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? R 13:56 0:00 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 13:56 0:00 [lru-add-drain]
[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 - 32069 ep_pol 13:56 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
1 S root 2 0 0 80 0 - 0 kthrea 13:56 ? 00:00:00 [kthreadd]
1 S root 3 2 0 80 0 - 0 smpboo 13:56 ? 00:00:00 [ksoftirqd/0]
1 S root 5 2 0 60 -20 - 0 worker 13:56 ? 00:00:00 [kworker/0:0H]
1 S root 7 2 0 -40 - - 0 smpboo 13:56 ? 00:00:00 [migration/0]
1 S root 8 2 0 80 0 - 0 rcu_gp 13:56 ? 00:00:00 [rcu_bh]
1 R root 9 2 0 80 0 - 0 - 13:56 ? 00:00:00 [rcu_sched]
1 S root 10 2 0 60 -20 - 0 rescue 13:56 ? 00:00:00 [lru-add-drain]
5 S root 11 2 0 -40 - - 0 smpboo 13:56 ? 00:00:00 [watchdog/0]
5 S root 13 2 0 80 0 - 0 devtmp 13:56 ? 00:00:00 [kdevtmpfs]
2、通过top命令查看进程
[root@localhost ~]# top -d 2
top - 16:05:17 up 2:08, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 258 total, 1 running, 257 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.5 us, 0.5 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 2028088 total, 622264 free, 714776 used, 691048 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1089856 avail Mem
3、通过pgrep命令查看sshd服务的进程号
[root@localhost ~]# pgrep -l "sshd"
7570 sshd
9252 sshd
4、查看系统进程树
[root@localhost ~]# pstree -aup
systemd,1 --switched-root --system --deserialize 22
├─ModemManager,6918
│ ├─{ModemManager},6934
│ └─{ModemManager},6944
├─NetworkManager,7071 --no-daemon
│ ├─{NetworkManager},7079
│ └─{NetworkManager},7082
├─VGAuthService,6946 -s
├─abrt-watch-log,6936 -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruptiondo_IRQ: stack overfl
├─abrt-watch-log,6962 -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
├─abrtd,6935 -d -s
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
记录了8190+0 的读入
记录了8190+0 的写出
8587837440字节(8.6 GB)已复制,28.8856 秒,297 MB/秒
[root@localhost ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 128276 6892 ? Ss 13:56 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 13:56 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 13:56 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 13:56 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 13:56 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 13:56 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? R 13:56 0:00 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 13:56 0:00 [lru-add-drain]
[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 - 32069 ep_pol 13:56 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
1 S root 2 0 0 80 0 - 0 kthrea 13:56 ? 00:00:00 [kthreadd]
1 S root 3 2 0 80 0 - 0 smpboo 13:56 ? 00:00:00 [ksoftirqd/0]
1 S root 5 2 0 60 -20 - 0 worker 13:56 ? 00:00:00 [kworker/0:0H]
1 S root 7 2 0 -40 - - 0 smpboo 13:56 ? 00:00:00 [migration/0]
1 S root 8 2 0 80 0 - 0 rcu_gp 13:56 ? 00:00:00 [rcu_bh]
1 R root 9 2 0 80 0 - 0 - 13:56 ? 00:00:00 [rcu_sched]
1 S root 10 2 0 60 -20 - 0 rescue 13:56 ? 00:00:00 [lru-add-drain]
5 S root 11 2 0 -40 - - 0 smpboo 13:56 ? 00:00:00 [watchdog/0]
5 S root 13 2 0 80 0 - 0 devtmp 13:56 ? 00:00:00 [kdevtmpfs]
2、通过top命令查看进程
[root@localhost ~]# top -d 2
top - 16:05:17 up 2:08, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 258 total, 1 running, 257 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.5 us, 0.5 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 2028088 total, 622264 free, 714776 used, 691048 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1089856 avail Mem
3、通过pgrep命令查看sshd服务的进程号
[root@localhost ~]# pgrep -l "sshd"
7570 sshd
9252 sshd
4、查看系统进程树
[root@localhost ~]# pstree -aup
systemd,1 --switched-root --system --deserialize 22
├─ModemManager,6918
│ ├─{ModemManager},6934
│ └─{ModemManager},6944
├─NetworkManager,7071 --no-daemon
│ ├─{NetworkManager},7079
│ └─{NetworkManager},7082
├─VGAuthService,6946 -s
├─abrt-watch-log,6936 -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruptiondo_IRQ: stack overfl
├─abrt-watch-log,6962 -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
├─abrtd,6935 -d -s
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
记录了8190+0 的读入
记录了8190+0 的写出
8587837440字节(8.6 GB)已复制,28.8856 秒,297 MB/秒
6、将第5题命令操作调入到后台并暂停
[root@localhost ~]# dd if=/dev/zero of=/root/file bs=1M count=8190
^Z
[2]+ 已停止 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=1024 &
[4] 10667
8、查看后台的任务列表
[root@localhost ~]# jobs -l
[1] 10568 停止 (信号) top -d 2
[2]- 10613 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[3]+ 10630 停止 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
[root@localhost ~]# fg 2
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 ~]# jobs -l
[1] 10568 停止 (信号) top -d 2
[2]- 10613 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[3] 10630 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[4]+ 10943 停止 crontab
[root@localhost ~]# kill -9 10613 | kill -9 10630
[2]- 已杀死 dd if=/dev/zero of=/root/file bs=1M count=8190
[3] 已杀死 dd if=/dev/zero of=/root/file bs=1M count=8190
11、设置一次性计划任务在18:00时关闭系统,并查看任务信息
[root@localhost ~]# date
2019年 08月 08日 星期四 16:18:39 CST
[root@localhost ~]# at 18:00
at> init 0
at> <EOT>
job 1 at Thu Aug 8 18:00:00 2019
12、以root身份设置周期性计划任务
[root@localhost ~]# nl /etc/crontab
1 SHELL=/bin/bash
2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
3 MAILTO=root
4 # For details see man 4 crontabs
5 # Example of job definition:
6 # .---------------- minute (0 - 59)
7 # | .------------- hour (0 - 23)
8 # | | .---------- day of month (1 - 31)
9 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
10 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
11 # | | | | |
12 # * * * * * user-name command to be executed
a) 每天晚上的24点时打包压缩 /etc/passwd /etc/shadow /etc/group /etc/gshadow 为 file.tar.gz
[root@localhost ~]# crontab -e
no crontab for root - using an empty one
[root@localhost ~]# dd if=/dev/zero of=/root/file bs=1M count=8190
^Z
[2]+ 已停止 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=1024 &
[4] 10667
8、查看后台的任务列表
[root@localhost ~]# jobs -l
[1] 10568 停止 (信号) top -d 2
[2]- 10613 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[3]+ 10630 停止 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
[root@localhost ~]# fg 2
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 ~]# jobs -l
[1] 10568 停止 (信号) top -d 2
[2]- 10613 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[3] 10630 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[4]+ 10943 停止 crontab
[root@localhost ~]# kill -9 10613 | kill -9 10630
[2]- 已杀死 dd if=/dev/zero of=/root/file bs=1M count=8190
[3] 已杀死 dd if=/dev/zero of=/root/file bs=1M count=8190
11、设置一次性计划任务在18:00时关闭系统,并查看任务信息
[root@localhost ~]# date
2019年 08月 08日 星期四 16:18:39 CST
[root@localhost ~]# at 18:00
at> init 0
at> <EOT>
job 1 at Thu Aug 8 18:00:00 2019
12、以root身份设置周期性计划任务
[root@localhost ~]# nl /etc/crontab
1 SHELL=/bin/bash
2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
3 MAILTO=root
4 # For details see man 4 crontabs
5 # Example of job definition:
6 # .---------------- minute (0 - 59)
7 # | .------------- hour (0 - 23)
8 # | | .---------- day of month (1 - 31)
9 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
10 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
11 # | | | | |
12 # * * * * * user-name command to be executed
a) 每天晚上的24点时打包压缩 /etc/passwd /etc/shadow /etc/group /etc/gshadow 为 file.tar.gz
[root@localhost ~]# crontab -e
no crontab for root - using an empty one
0 0 * * * tar zcf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
b) 每周一的每隔五分钟列出磁盘使用状况
*/5 * * * 1 df -Th
c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间
30 8 * * * ntpdate poll.ntp.org
13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容
[root@localhost ~]# crontab -l
0 0 * * * tar zcf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
*/5 * * * 1 df -Th
30 8 * * * ntpdate poll.ntp.org
[root@localhost ~]# cat -n /var/spool/cron/root
1 0 0 * * * tar zcf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
2 */5 * * * 1 df -Th
3 30 8 * * * ntpdate poll.ntp.org
b) 每周一的每隔五分钟列出磁盘使用状况
*/5 * * * 1 df -Th
c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间
30 8 * * * ntpdate poll.ntp.org
13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容
[root@localhost ~]# crontab -l
0 0 * * * tar zcf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
*/5 * * * 1 df -Th
30 8 * * * ntpdate poll.ntp.org
[root@localhost ~]# cat -n /var/spool/cron/root
1 0 0 * * * tar zcf file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
2 */5 * * * 1 df -Th
3 30 8 * * * ntpdate poll.ntp.org