一、經過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]
二、經過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
三、經過pgrep命令查看sshd服務的進程號
[root@localhost ~]# pgrep -l "sshd"
7570 sshd
9252 sshd
四、查看系統進程樹
[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
五、使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/秒
六、將第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
七、使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
八、查看後臺的任務列表
[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
九、恢復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
十、查詢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
十一、設置一次性計劃任務在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
十二、以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
1三、經過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