1、通过ps命令的两种选项形式查看进程信息
(1)
[root@localhost ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 56620 6748 ? Ss 8月07 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 24
root 2 0.0 0.0 0 0 ? S 8月07 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 8月07 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 8月07 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 8月07 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 8月07 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 8月07 0:00 [rcuob/0]
root 10 0.0 0.0 0 0 ? S 8月07 0:00 [rcuob/1]
root 11 0.0 0.0 0 0 ? S 8月07 0:00 [rcuob/2]
(2)
[root@localhost ~]# ps -efl
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 S root 1 0 0 80 0 - 14155 ep_pol 8月07 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deseria
1 S root 2 0 0 80 0 - 0 kthrea 8月07 ? 00:00:00 [kthreadd]
1 S root 3 2 0 80 0 - 0 smpboo 8月07 ? 00:00:00 [ksoftirqd/0]
1 S root 5 2 0 60 -20 - 0 worker 8月07 ? 00:00:00 [kworker/0:0H]
1 S root 7 2 0 -40 - - 0 smpboo 8月07 ? 00:00:00 [migration/0]
1 S root 8 2 0 80 0 - 0 rcu_gp 8月07 ? 00:00:00 [rcu_bh]
1 S root 9 2 0 80 0 - 0 rcu_no 8月07 ? 00:00:00 [rcuob/0]
1 S root 10 2 0 80 0 - 0 rcu_no 8月07 ? 00:00:00 [rcuob/1]
1 S root 11 2 0 80 0 - 0 rcu_no 8月07 ? 00:00:00 [rcuob/2]
1 S root 12 2 0 80 0 - 0 rcu_no 8月07 ? 00:00:00 [rcuob/3]
2、通过top命令查看进程
[root@localhost ~]# top
top - 04:08:08 up 6:59, 3 users, load average: 0.00, 0.01, 0.05
Tasks: 405 total, 3 running, 402 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 : 2035356 total, 1655860 free, 139140 used, 240356 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1723932 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2341 root 20 0 0 0 0 R 0.3 0.0 0:02.05 kworker/0:2
1 root 20 0 56620 6748 3940 S 0.0 0.3 0:02.04 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:00.19 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuo
3、通过pgrep命令查看sshd服务的进程号
[root@localhost ~]# pgrep -l sshd
1494 sshd
2090 sshd
2168 sshd
2195 sshd
4、查看系统进程树
[root@localhost ~]# pstree
systemd─┬─NetworkManager───3*[{NetworkManager}]
├─agetty
├─atd
├─auditd───{auditd}
├─crond
├─dbus-daemon───{dbus-daemon}
├─firewalld───{firewalld}
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5*[{polkitd}]
├─rsyslogd───2*[{rsyslogd}]
├─sshd───sshd───bash───pstree
├─systemd-journal
├─systemd-logind
├─systemd-udevd
└─tuned───4*[{tuned}]
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
^C记录了278+0 的读入
记录了278+0 的写出
291504128字节(292 MB)已复制,14.9926 秒,19.4 MB/秒
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/file bs=1M count=8190 &
[2] 2366
8、查看后台的任务列表
[root@localhost ~]# jobs -l
[1]+ 2364 停止 dd if=/dev/zero of=/root/file bs=1M count=8190
[2]- 2366 运行中 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 ~]# jobs -l
[1]+ 2364 停止 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 -l
[1]+ 2364 运行中 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]+ 2364 运行中 dd if=/dev/zero of=/root/file bs=1M count=8190 &
[root@localhost ~]# ps aux | grep dd
root 2 0.0 0.0 0 0 ? S 8月07 0:00 [kthreadd]
dbus 941 0.0 0.0 34880 1904 ? Ssl 8月07 0:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 2364 21.4 0.0 108956 1672 pts/0 D 04:19 1:00 dd if=/dev/zero of=/root/file bs=1M count=8190
root 2371 0.0 0.0 112660 972 pts/0 S+ 04:24 0:00 grep --color=auto dd
[root@localhost ~]# kill -9 2364
[root@localhost ~]# jobs -l
[1]+ 2364 已杀死 dd if=/dev/zero of=/root/file bs=1M count=8190
11、设置一次性计划任务在18:00时关闭系统,并查看任务信息
[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
[root@localhost ~]# atrm 1
[root@localhost ~]# atq
12、以root身份设置周期性计划任务
a) 每天晚上的24点时打包压缩 /etc/passwd /etc/shadow /etc/group /etc/gshadow 为 file.tar.gz
tar -czf /root/file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
b) 每周一的每隔五分钟列出磁盘使用状况
*/5 * * * 1 df -hT
c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间
30 8 * * * ntpdate pool.ntp.org
13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容
[root@localhost ~]# crontab -l
0 0 * * * tar -czf /root/file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
*/5 * * * 1 df -hT
30 8 * * * ntpdate pool.ntp.org
[root@localhost ~]# cat /var/spool/cron/root
0 0 * * * tar -czf /root/file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
*/5 * * * 1 df -hT
30 8 * * * ntpdate pool.ntp.org