1、通过ps命令的两种选项形式查看进程信息
[root@localhost ~]# ps aux | head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.5 60516 5144 ? Ss 08:28 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 2 0.0 0.0 0 0 ? S 08:28 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 08:28 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 08:28 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 08:28 0:00 [kworker/u256:0]
root 7 0.0 0.0 0 0 ? S 08:28 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 08:28 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 08:28 0:00 [rcuob/0]
root 10 0.0 0.0 0 0 ? S 08:28 0:00 [rcuob/1]
[root@localhost ~]# ps -lef | head
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 S root 1 0 0 80 0 - 15129 ep_pol 08:28 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
1 S root 2 0 0 80 0 - 0 kthrea 08:28 ? 00:00:00 [kthreadd]
1 S root 3 2 0 80 0 - 0 smpboo 08:28 ? 00:00:00 [ksoftirqd/0]
1 S root 5 2 0 60 -20 - 0 worker 08:28 ? 00:00:00 [kworker/0:0H]
1 S root 6 2 0 80 0 - 0 worker 08:28 ? 00:00:00 [kworker/u256:0]
1 S root 7 2 0 -40 - - 0 smpboo 08:28 ? 00:00:00 [migration/0]
1 S root 8 2 0 80 0 - 0 rcu_gp 08:28 ? 00:00:00 [rcu_bh]
1 S root 9 2 0 80 0 - 0 rcu_no 08:28 ? 00:00:00 [rcuob/0]
1 S root 10 2 0 80 0 - 0 rcu_no 08:28 ? 00:00:00 [rcuob/1]
2、通过top命令查看进程
top - 10:49:31 up 2:21, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 406 total, 2 running, 404 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 : 1003160 total, 95928 free, 559836 used, 347396 buff/cache
KiB Swap: 2097148 total, 2055656 free, 41492 used. 197736 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
873 root 20 0 269016 1976 1564 S 0.3 0.2 0:14.34 vmtoolsd
33451 root 20 0 130300 2104 1268 R 0.3 0.2 0:00.40 top
1 root 20 0 60516 5144 1732 S 0.0 0.5 0:02.44 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.78 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.40 kworker/u256:0
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 rcuob/0
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/1
[root@localhost ~]# top -b -n 2 > /tmp/top.txt
[root@localhost ~]# ls /tmp
hsperfdata_root systemd-private-i9UXk3 top.txt
yum_save_tx.2019-08-05.08-56.2gZYlf.yumtx
[root@localhost ~]# cat /tmp/top.txt | head
top - 10:50:34 up 2:22, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 405 total, 3 running, 402 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.0 us, 1.1 sy, 0.4 ni, 94.7 id, 0.5 wa, 0.0 hi, 0.2 si, 0.0 st
KiB Mem : 1003160 total, 95944 free, 559808 used, 347408 buff/cache
KiB Swap: 2097148 total, 2055668 free, 41480 used. 197752 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
33467 root 20 0 130152 1872 1204 R 10.5 0.2 0:00.37 top
2166 root 20 0 461636 5644 1472 S 5.3 0.6 0:00.12 ibus-daemon
1 root 20 0 60516 5144 1732 S 0.0 0.5 0:02.48 systemd
3、通过pgrep命令查看sshd服务的进程号
[root@localhost ~]# pgrep -l sshd
1369 sshd
2756 sshd
4、查看系统进程树
[root@localhost ~]# pstree
systemd─┬─ModemManager───2*[{ModemManager}]
├─NetworkManager─┬─dhclient
│ └─3*[{NetworkManager}]
├─2*[abrt-watch-log]
├─abrtd
├─accounts-daemon───2*[{accounts-daemon}]
├─alsactl
├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon}
│ └─3*[{at-spi-bus-laun}]
├─at-spi2-registr───{at-spi2-registr}
├─atd
├─auditd─┬─audispd─┬─sedispatch
│ │ └─{audispd}
│ └─{auditd}
├─avahi-daemon───avahi-daemon
├─bluetoothd
├─chronyd
├─colord───2*[{colord}]
├─crond
├─cupsd
├─2*[dbus-daemon───{dbus-daemon}]
├─dbus-launch
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
[root@localhost ~]# jobs
[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=1024 &
[2] 33683
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=1024 &
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 &
10、查询dd if=/dev/zero of=/root/file bs=1M count=8190 命令的进程并通过kill杀死
[root@localhost ~]# ps aux | grep dd
root 2 0.0 0.0 0 0 ? S 08:28 0:00 [kthreadd]
root 876 0.0 0.0 212056 904 ? Ss 08:28 0:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruption do_IRQ: stack overflow: ear stack overflow (cur: eneral protection fault nable to handle kernel ouble fault: RTNL: assertion failed eek! page_mapcount(page) went negative! adness at NETDEV WATCHDOG ysctl table check failed : nobody cared IRQ handler type mismatch Machine Check Exception: Machine check events logged divide error: bounds: coprocessor segment overrun: invalid TSS: segment not present: invalid opcode: alignment check: stack segment: fpu exception: simd exception: iret exception: /var/log/messages -- /usr/bin/abrt-dump-oops -xtD
dbus 901 0.0 0.2 38432 2744 ? Ssl 08:28 0:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 1888 0.0 0.2 38152 2088 ? Ssl 08:30 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
root 2038 0.0 0.1 36836 1412 ? Sl 08:30 0:00 /bin/dbus-daemon --config-file=/etc/at-spi2/accessibility.conf --nofork --print-address 3
root 2233 0.0 0.6 878744 6224 ? Sl 08:31 0:00 /usr/libexec/evolution-addressbook-factory
root 33745 11.0 0.1 108956 1672 pts/2 R+ 11:08 0:00 dd if=/dev/zero of=/root/file bs=1M count=8190
root 33747 9.0 0.0 112660 968 pts/1 R+ 11:08 0:00 grep --color=auto dd
[root@localhost ~]# kill 33745
[root@localhost ~]# ps aux | grep dd
root 2 0.0 0.0 0 0 ? S 08:28 0:00 [kthreadd]
root 876 0.0 0.0 212056 904 ? Ss 08:28 0:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking detected ernel BUG at list_del corruption list_add corruption do_IRQ: stack overflow: ear stack overflow (cur: eneral protection fault nable to handle kernel ouble fault: RTNL: assertion failed eek! page_mapcount(page) went negative! adness at NETDEV WATCHDOG ysctl table check failed : nobody cared IRQ handler type mismatch Machine Check Exception: Machine check events logged divide error: bounds: coprocessor segment overrun: invalid TSS: segment not present: invalid opcode: alignment check: stack segment: fpu exception: simd exception: iret exception: /var/log/messages -- /usr/bin/abrt-dump-oops -xtD
dbus 901 0.0 0.2 38432 2744 ? Ssl 08:28 0:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 1888 0.0 0.2 38152 2088 ? Ssl 08:30 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
root 2038 0.0 0.1 36836 1412 ? Sl 08:30 0:00 /bin/dbus-daemon --config-file=/etc/at-spi2/accessibility.conf --nofork --print-address 3
root 2233 0.0 0.6 878744 6224 ? Sl 08:31 0:00 /usr/libexec/evolution-addressbook-factory
root 33758 0.0 0.0 112660 972 pts/1 R+ 11:09 0:00 grep --color=auto dd
11、设置一次性计划任务在18:00时关闭系统,并查看任务信息
[root@localhost ~]# at 18:00
at> init 0
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
0 0 * * * /bin/tar cfz /tmp/file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
b) 每周一的每隔五分钟列出磁盘使用状况
*/5 * * * 1 /usr/bin/df -hT
c) 每天的8:30与互联网时间同步服务器pool.ntp.org同步时间
30 8 * * * /usr/sbin/ntpdate pool.ntp.org
13、通过crontab命令查看root的计划任务,通过文件查看类工具列出/var/spool/cron下对应的文件内容
[root@localhost ~]# crontab -l
0 0 * * * /bin/tar cfz /tmp/file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
*/5 * * * 1 /usr/bin/df -hT
30 8 * * * /usr/sbin/ntpdate pool.ntp.org
[root@localhost ~]# cat /var/spool/cron/root
0 0 * * * /bin/tar cfz /tmp/file.tar.gz /etc/passwd /etc/shadow /etc/group /etc/gshadow
*/5 * * * 1 /usr/bin/df -hT
30 8 * * * /usr/sbin/ntpdate pool.ntp.org