0
点赞
收藏
分享

微信扫一扫

管理进程及设置计划任务

westfallon 2022-07-12 阅读 82

实验环境

  • 为了更好地了解和控制Linux服务器的有序运行,管理员需要对系统中的进程进行管理并设置计划任务来有效地监控与维护Linux服务器的正常运行

需求描述

1.管理系统中的进程

  • 使用kill 命令终止sshd服务的运行

[root@localhost /]# pgrep -l "sshd"
1116 sshd
1782 sshd
[root@localhost /]# kill 1116
[root@localhost /]# pgrep -l "sshd"
1782 sshd
[root@localhost /]#

  • 查找系统中 CPU占用率超过80%的进程,并强行终止该进程

[root@localhost /]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.5 0.7 128368 6988 ? Ss 09:45 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 09:45 0:00 [kthreadd]
root 4 0.0 0.0 0 0 ? S< 09:45 0:00 [kworker/0:0H]
root 5 0.0 0.0 0 0 ? S 09:45 0:00 [kworker/u256:0]
root 6 0.0 0.0 0 0 ? S 09:45 0:00 [ksoftirqd/0]
root 7 0.0 0.0 0 0 ? S 09:45 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 09:45 0:00 [rcu_bh]
root 9 0.1 0.0 0 0 ? R 09:45 0:00 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 09:45 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 09:45 0:00 [watchdog/0]
root 13 0.0 0.0 0 0 ? S 09:45 0:00 [kdevtmpfs]
root 14 0.0 0.0 0 0 ? S< 09:45 0:00 [netns]
root 15 0.0 0.0 0 0 ? S 09:45 0:00 [khungtaskd]
root 16 0.0 0.0 0 0 ? S< 09:45 0:00 [writeback]
root 17 0.0 0.0 0 0 ? S< 09:45 0:00 [kintegrityd]
root 18 0.0 0.0 0 0 ? S< 09:45 0:00 [bioset]
root 19 0.0 0.0 0 0 ? S< 09:45 0:00 [bioset]
root 20 0.0 0.0 0 0 ? S< 09:45 0:00 [bioset]
root 21 0.0 0.0 0 0 ? S< 09:45 0:00 [kblockd]
root 22 0.0 0.0 0 0 ? S< 09:45 0:00 [md]
root 23 0.0 0.0 0 0 ? S< 09:45 0:00 [edac-poller]
root 24 0.0 0.0 0 0 ? S< 09:45 0:00 [watchdogd]
root 25 0.0 0.0 0 0 ? S 09:45 0:00 [kworker/0:1]
root 30 0.0 0.0 0 0 ? S 09:45 0:00 [kswapd0]
root 31 0.0 0.0 0 0 ? SN 09:45 0:00 [ksmd]
root 32 0.0 0.0 0 0 ? SN 09:45 0:00 [khugepaged]
root 33 0.0 0.0 0 0 ? S< 09:45 0:00 [crypto]
root 41 0.0 0.0 0 0 ? S< 09:45 0:00 [kthrotld]
root 43 0.0 0.0 0 0 ? S< 09:45 0:00 [kmpath_rdacd]
root 44 0.0 0.0 0 0 ? S< 09:45 0:00 [kaluad]
root 45 0.0 0.0 0 0 ? S< 09:45 0:00 [kpsmoused]
root 47 0.0 0.0 0 0 ? S< 09:45 0:00 [ipv6_addrconf]
root 60 0.0 0.0 0 0 ? S< 09:45 0:00 [deferwq]
root 95 0.0 0.0 0 0 ? S 09:45 0:00 [kauditd]
root 127 0.0 0.0 0 0 ? S 09:45 0:00 [kworker/0:3]
root 238 0.0 0.0 0 0 ? S< 09:45 0:00 [mpt_poll_0]
root 239 0.0 0.0 0 0 ? S< 09:45 0:00 [ata_sff]
root 240 0.0 0.0 0 0 ? S< 09:45 0:00 [mpt/0]
root 245 0.0 0.0 0 0 ? S< 09:45 0:00 [nfit]
root 249 0.0 0.0 0 0 ? S 09:45 0:00 [scsi_eh_0]
root 250 0.0 0.0 0 0 ? S< 09:45 0:00 [scsi_tmf_0]
root 251 0.0 0.0 0 0 ? S 09:45 0:00 [scsi_eh_1]
root 252 0.0 0.0 0 0 ? S 09:45 0:00 [kworker/u256:2]
root 253 0.0 0.0 0 0 ? S< 09:45 0:00 [scsi_tmf_1]
root 254 0.0 0.0 0 0 ? S 09:45 0:00 [scsi_eh_2]
root 255 0.0 0.0 0 0 ? S< 09:45 0:00 [scsi_tmf_2]
root 257 0.0 0.0 0 0 ? S 09:45 0:00 [irq/16-vmwgfx]
root 258 0.0 0.0 0 0 ? S< 09:45 0:00 [ttm_swap]
root 287 0.0 0.0 0 0 ? S< 09:45 0:00 [bioset]
root 288 0.0 0.0 0 0 ? S< 09:45 0:00 [xfsalloc]
root 289 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs_mru_cache]
root 290 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-buf/sda3]
root 291 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-data/sda3]
root 292 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-conv/sda3]
root 293 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-cil/sda3]
root 294 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-reclaim/sda]
root 295 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-log/sda3]
root 296 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-eofblocks/s]
root 297 0.0 0.0 0 0 ? S 09:45 0:00 [xfsaild/sda3]
root 298 0.0 0.0 0 0 ? S< 09:45 0:00 [kworker/0:1H]
root 380 0.0 0.3 37344 3472 ? Ss 09:45 0:00 /usr/lib/systemd/systemd-journald
root 409 0.0 0.4 266644 4176 ? Ss 09:45 0:00 /usr/sbin/lvmetad -f
root 419 0.0 0.5 49292 5704 ? Ss 09:45 0:00 /usr/lib/systemd/systemd-udevd
root 471 0.0 0.0 0 0 ? S< 09:45 0:00 [hci0]
root 472 0.0 0.0 0 0 ? S< 09:45 0:00 [hci0]
root 473 0.0 0.0 0 0 ? S< 09:45 0:00 [kworker/u257:1]
root 474 0.0 0.0 0 0 ? S< 09:45 0:00 [kworker/u257:2]
root 504 0.0 0.0 0 0 ? S< 09:45 0:00 [kdmflush]
root 505 0.0 0.0 0 0 ? S< 09:45 0:00 [bioset]
root 515 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-buf/sda1]
root 517 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-data/sda1]
root 520 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-conv/sda1]
root 522 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-cil/sda1]
root 524 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-reclaim/sda]
root 526 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-log/sda1]
root 529 0.0 0.0 0 0 ? S< 09:45 0:00 [xfs-eofblocks/s]
root 533 0.0 0.0 0 0 ? S 09:45 0:00 [xfsaild/sda1]
root 582 0.0 0.0 55532 852 ? S<sl 09:45 0:00 /sbin/auditd
root 584 0.0 0.0 84556 812 ? S<sl 09:45 0:00 /sbin/audispd
root 586 0.0 0.1 55620 1380 ? S< 09:45 0:00 /usr/sbin/sedispatch
root 588 0.0 0.0 0 0 ? S< 09:45 0:00 [rpciod]
root 589 0.0 0.0 0 0 ? S< 09:45 0:00 [xprtiod]
root 611 0.0 0.5 168304 5176 ? Ss 09:45 0:00 /usr/bin/VGAuthService -s
root 612 0.2 0.5 295564 5292 ? Ssl 09:45 0:00 /usr/bin/vmtoolsd
root 613 0.0 0.1 16900 1376 ? SNs 09:45 0:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa
root 614 0.0 0.2 57504 2552 ? Ss 09:45 0:00 /usr/libexec/bluetooth/bluetoothd
root 615 0.0 0.1 26444 1812 ? Ss 09:45 0:00 /usr/lib/systemd/systemd-logind
rpc 616 0.0 0.1 69256 1012 ? Ss 09:45 0:00 /sbin/rpcbind -w
root 617 0.0 0.7 430628 7540 ? Ssl 09:45 0:00 /usr/sbin/ModemManager
root 620 0.0 0.2 52880 2748 ? Ss 09:45 0:00 /usr/sbin/smartd -n -q never
root 621 0.0 0.5 228408 5864 ? Ss 09:45 0:00 /usr/sbin/abrtd -d -s
root 623 0.0 0.4 225916 4892 ? Ss 09:45 0:00 /usr/bin/abrt-watch-log -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
root 624 0.0 0.6 451300 6520 ? Ssl 09:45 0:00 /usr/libexec/udisks2/udisksd
avahi 625 0.0 0.2 62264 2260 ? Ss 09:45 0:00 avahi-daemon: running [linux.local]
libstor+ 629 0.0 0.0 8580 820 ? Ss 09:45 0:00 /usr/bin/lsmd -d
root 634 0.1 0.3 90568 3180 ? Ss 09:45 0:00 /sbin/rngd -f
chrony 638 0.0 0.1 117808 1728 ? S 09:45 0:00 /usr/sbin/chronyd
root 643 0.0 0.4 396664 4220 ? Ssl 09:45 0:00 /usr/libexec/accounts-daemon
rtkit 651 0.0 0.1 198784 1772 ? SNsl 09:45 0:00 /usr/libexec/rtkit-daemon
polkitd 652 0.1 1.4 616360 14812 ? Ssl 09:45 0:00 /usr/lib/polkit-1/polkitd --no-debug
dbus 656 0.0 0.3 69788 3536 ? Ssl 09:45 0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
avahi 657 0.0 0.0 62140 400 ? S 09:45 0:00 avahi-daemon: chroot helper
root 664 0.0 0.1 201428 1268 ? Ssl 09:45 0:00 /usr/sbin/gssproxy -D
root 689 0.0 0.4 225916 4896 ? Ss 09:45 0:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive locking de
root 726 0.1 2.9 359112 29808 ? Ssl 09:45 0:00 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
root 733 0.0 0.0 115408 940 ? S 09:45 0:00 /bin/bash /usr/sbin/ksmtuned
root 785 0.0 1.2 715960 12184 ? Ssl 09:45 0:00 /usr/sbin/NetworkManager --no-daemon
root 914 0.0 0.5 102904 5480 ? S 09:45 0:00 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-ens33.pid -lf /var
root 1108 0.0 1.7 574288 17504 ? Ssl 09:45 0:00 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root 1111 0.0 0.4 214432 4112 ? Ssl 09:45 0:00 /usr/sbin/rsyslogd -n
root 1113 0.0 0.4 198072 4276 ? Ss 09:45 0:00 /usr/sbin/cupsd -f
root 1118 0.1 1.8 1007252 18768 ? Ssl 09:45 0:00 /usr/sbin/libvirtd
root 1130 0.0 0.4 481560 4656 ? Ssl 09:45 0:00 /usr/sbin/gdm
root 1131 0.0 0.0 25908 920 ? Ss 09:45 0:00 /usr/sbin/atd -f
root 1132 0.1 0.1 126380 1676 ? Ss 09:45 0:00 /usr/sbin/crond -n
nobody 1318 0.0 0.1 53876 1088 ? S 09:45 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-scr
root 1320 0.0 0.0 53848 380 ? S 09:45 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-scr
root 1411 0.0 0.2 91792 2156 ? Ss 09:45 0:00 /usr/libexec/postfix/master -w
postfix 1422 0.0 0.4 91896 4088 ? S 09:45 0:00 pickup -l -t unix -u
postfix 1423 0.0 0.4 91964 4104 ? S 09:45 0:00 qmgr -l -t unix -u
root 1497 0.1 2.8 287808 28260 tty1 Ssl+ 09:45 0:00 /usr/bin/X :0 -background none -noreset -audit 4 -verbose -auth /run/gdm/auth-for-gdm-HCrYba/
root 1508 0.0 0.4 363244 4872 ? Sl 09:45 0:00 gdm-session-worker [pam/gdm-launch-environment]
gdm 1512 0.0 0.9 671484 9136 ? Ssl 09:45 0:00 /usr/libexec/gnome-session-binary --autostart /usr/share/gdm/greeter/autostart
gdm 1517 0.0 0.0 59016 964 ? S 09:45 0:00 dbus-launch --exit-with-session /usr/libexec/gnome-session-binary --autostart /usr/share/gdm/
gdm 1518 0.0 0.2 68712 2036 ? Ssl 09:45 0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
gdm 1522 0.0 0.3 346788 3608 ? Sl 09:45 0:00 /usr/libexec/at-spi-bus-launcher
gdm 1527 0.0 0.2 68392 2396 ? Sl 09:45 0:00 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --
gdm 1531 0.0 0.3 233104 3948 ? Sl 09:45 0:00 /usr/libexec/at-spi2-registryd --use-gnome-session
gdm 1552 0.9 13.9 2942852 138496 ? Sl 09:45 0:03 /usr/bin/gnome-shell
root 1559 0.0 0.5 430484 5280 ? Ssl 09:45 0:00 /usr/libexec/upowerd
gdm 1577 0.0 0.6 1252312 6396 ? S<l 09:45 0:00 /usr/bin/pulseaudio --start --log-target=syslog
gdm 1593 0.0 0.5 461516 5532 ? Sl 09:45 0:00 ibus-daemon --xim --panel disable
gdm 1596 0.0 0.3 376172 3580 ? Sl 09:45 0:00 /usr/libexec/ibus-dconf
gdm 1600 0.0 1.3 465116 13848 ? Sl 09:45 0:00 /usr/libexec/ibus-x11 --kill-daemon
gdm 1603 0.0 0.3 376152 3452 ? Sl 09:45 0:00 /usr/libexec/ibus-portal
gdm 1613 0.0 0.2 364920 2892 ? Sl 09:45 0:00 /usr/libexec/xdg-permission-store
root 1623 0.0 0.4 398900 4144 ? Ssl 09:45 0:00 /usr/libexec/boltd
root 1626 0.0 0.5 410768 5504 ? Ssl 09:45 0:00 /usr/libexec/packagekitd
root 1632 0.0 0.3 78660 3336 ? Ss 09:45 0:00 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplic
gdm 1637 0.0 1.5 615516 15104 ? Sl 09:45 0:00 /usr/libexec/gsd-xsettings
gdm 1638 0.0 0.3 376704 3428 ? Sl 09:45 0:00 /usr/libexec/gsd-a11y-settings
gdm 1640 0.0 1.3 464792 13628 ? Sl 09:45 0:00 /usr/libexec/gsd-clipboard
gdm 1643 0.0 1.4 714412 14780 ? Sl 09:45 0:00 /usr/libexec/gsd-color
gdm 1647 0.0 0.8 465660 7976 ? Sl 09:45 0:00 /usr/libexec/gsd-datetime
gdm 1649 0.0 0.3 380888 3000 ? Sl 09:45 0:00 /usr/libexec/gsd-housekeeping
gdm 1653 0.0 1.3 614512 13868 ? Sl 09:45 0:00 /usr/libexec/gsd-keyboard
gdm 1661 0.0 1.5 1012408 15860 ? Sl 09:45 0:00 /usr/libexec/gsd-media-keys
gdm 1662 0.0 0.2 300620 2892 ? Sl 09:45 0:00 /usr/libexec/gsd-mouse
gdm 1668 0.0 1.5 705760 14936 ? Sl 09:45 0:00 /usr/libexec/gsd-power
gdm 1670 0.0 0.4 363352 4540 ? Sl 09:45 0:00 /usr/libexec/gsd-print-notifications
gdm 1674 0.0 0.3 317852 3100 ? Sl 09:45 0:00 /usr/libexec/gsd-rfkill
gdm 1681 0.0 0.3 374356 3104 ? Sl 09:45 0:00 /usr/libexec/gsd-screensaver-proxy
gdm 1686 0.0 0.4 411716 4332 ? Sl 09:45 0:00 /usr/libexec/gsd-sharing
gdm 1691 0.0 0.5 472440 5184 ? Sl 09:45 0:00 /usr/libexec/gsd-smartcard
gdm 1695 0.0 0.4 455208 4920 ? Sl 09:45 0:00 /usr/libexec/gsd-sound
gdm 1698 0.0 1.4 623316 14400 ? Sl 09:45 0:00 /usr/libexec/gsd-wacom
colord 1720 0.0 0.6 419808 6432 ? Ssl 09:45 0:00 /usr/libexec/colord
gdm 1743 0.0 0.3 302356 3400 ? Sl 09:45 0:00 /usr/libexec/ibus-engine-simple
root 1782 0.0 0.5 160988 5640 ? Ss 09:46 0:00 sshd: root@pts/0
root 1790 0.0 0.3 116964 3668 pts/0 Ss 09:46 0:00 -bash
root 1928 0.0 0.0 0 0 ? R 09:50 0:00 [kworker/0:0]
root 1932 0.0 0.0 0 0 ? S 09:51 0:00 [kworker/0:2]
root 1940 0.0 0.0 108052 352 ? S 09:51 0:00 sleep 60
root 1941 0.0 0.1 155448 1868 pts/0 R+ 09:51 0:00 ps aux
[root@localhost /]#
[root@localhost /]# kill 1941

2.设置计划运行的系统管理任务。

  • 每周一的早上7:50 自动清空FTP服务器公共目录/var/ftp/pub中的数据。

[root@localhost /]# crontab -e

50 7 * * 1 /usr/bin/rm -rf /var/ftp/pub/*

  • 每天晚上的 10:30自动执行任务,完成以下操作:显示当前的系统时间并查看已挂载磁盘分区的磁盘使用情况,将输出结果追加保存到文件/var/og/df .log 中,以便持续观察硬盘空间的变化。

[root@localhost /]# crontab -e

50 7 * * 1 /usr/bin/rm -rf /var/ftp/pub/*
30 10 * * * /usr/bin/date /usr/bin/df -hT | col -b > /var/log/df.log

  • 确认所设置的计 划任务列表。

[root@localhost /]# crontab -l
50 7 * * 1 /usr/bin/rm -rf /var/ftp/pub/*
30 10 * * * /usr/bin/date /usr/bin/df -hT | col -b > /var/log/df.log
[root@localhost /]#

举报

相关推荐

0 条评论