Proj. 5 Service & Process Management
Proj. 5 Service & Process Management
1. Overview
At any given moment, there are anywhere from dozens to thousands of process
running on a Unix system. The large majority of these processes, called daemons, run
in the background. Daemons are crucial to having a usable system and provide much
of a system’s core functionality, including the graphics server, sound server, and
Today we’ll explore these background processes and create some of our own! Make
sure the following exercises are executed on your VM unless explicitly specified
otherwise.
在任何给定的时刻,Unix 系统上都有几十到几千个进程在运行。这些进程中的大部分
称为守护进程,在后台运行。守护进程对于拥有一个可用的系统至关重要,它提供了
系统的许多核心功能,包括图形服务器、声音服务器和网络服务等等。
今天我们将探索这些背景过程,并创建一些自己的!除非另有明确说明,否则请确保
在 VM 上执行以下练习。
2. Tutorial
running. You should see something like this: PID TTY TIME CMD 3634 pts/2
2. 1.打开终端,运行 ps 命令,查看正在运行的进程。你应该看到这样的东西:
PID TTY TIME CMD 3634 pts/2 00:00:00 ps 15015 pts/2 00:00:00 bash
3. ps
4.
5. ps -aux
6. Now open up another terminal and run sleep 1000 in the background, you
should get an output like “[1] 29756”, which gives the process id. Then run
10. In the first terminal run ps again. You should notice that the sleep process is
not showing up, even though the thousand seconds haven’t expired. (Exercise
12. We can get the process to display on the first terminal by running ps -u, which
displays all the processes running as your user. Notice the PID column; each
process has a unique ID assigned to it by the kernel. One thing we can do with
this PID is send signals to the process. “sleep 1000” is pretty useless, so go
ahead and kill it – kill 29756 (substitute 29756 with whatever PID ps outputted
for you).
15. The most common use of ps is to run ps -ef to see all the processes running
on the system. Run ps -e and ps -f independently to see how the flags work
together.
和 ps-f 以查看标志如何协同工作。
17. ps –e
18. ps -f
19. Make sure htop is installed by running sudo apt install htop.
22. Now, open up a terminal and run the htop command. htop can be thought of
real-time.
25. First press <F2>, scroll down to Display options, and check “Hide userland
26. 首先按<F2>,向下滚动显示选项,并选中“隐藏用户和进程线程”。我们将不
会在这个实验室处理这些线程。
27. Now open up another terminal. Run the command yes. It uses a lot of
specifically does the yes command exhaust? If you are having trouble
finding this, press < to choose which resource to order processes by. Make
资源订购流程。完成后,请确保退出“是”(^C)。
29. yes
30. ^C
31. Run htop once more. This time click <F5> to enter Tree View. You should see a
stemming from /sbin/init (systemd).
次结构的可视化表示,所有内容都源于/sbin/init(systemd)。
************************Orphan processes***********************************
33.Open a second terminal. Now run sleep 1000 &. You should see this new
(练习 3)它的父对象是什么?
35.
36. Select this parent and press <F9> to kill it. Send the SIGTERM signal. The sleep
process now has init as its new parent, which is PID 1. What you just did is
re-parented by the init process.
38. Now go through the same steps again. This time, send the parent
a SIGHUP (hangup) signal. Can you still find the sleep process? When SIGHUP is
sent to a parent shell, the parent subsequently sends hangup signals to any
processes.
39. 37.现在再重复同样的步骤。这一次,给家长发一个叹息(挂机)信号。你还能
40. 如果你有兴趣了解不同的信号
42. Open the cron editor by running crontab -e (if the editor of your choice isn’t
being launched, set the EDITOR environment variable), which will create a
crontab for your user. Below is a sample task. Put this in your crontab:
把这个放到你的 crontab 中:
28. Right now this runs every minute. Modify it to run every five minutes and
quit out of the editor. Make sure to leave this running while you complete the
remainder of the lab as you will be turning this file in. If you get stuck, visit
crontab.guru!
28 现在每分钟一次。修改为每五分钟运行一次并退出编辑器。请确保在完成实
验室的其余部分时保持此运行,因为您将要提交此文件。如果你被困住了,请
访问 crontab.guru!
**********************************Job Control**********************************
46. Open 2 terminals. In one panel, change to the directory including the file
job.sh, and run ./job.sh > ~/count. Then, in the other panel, run less +F
~/count. You should see the less command increments every half a second or
so. Now run Ctrl+Z in the panel with the job.sh command. This will suspend
the process. (Exercise 5) What happens when you suspend the job
command?
行./job.sh>~/count。然后,在另一个面板中,运行更少的+F~/count。您应
Ctrl+Z。这将暂停进程。(练习 5)暂停作业命令时会发生什么情况?
just run bg. (Exercise 6) What happens after running the bg command?
52. 50.现在,让我们继续我们暂停的程序。既然我们只有一份工作,我们就可以运
53. bg
54. Now let’s bring our job to the foreground. First run jobs -l. You should see
both the job number (in brackets) and the pid of the job. We’ll bring the job to
brackets when you ran jobs -l) and kill it using Ctrl+C.
56. jobs –l
https://www.percona.com/downloads/Percona-Server-LATEST/
58. Download the Source
LATEST/Percona-Server-5.7.18-14/source/tarball/percona-server-5.7.18-
14.tar.gz
62. Change Directories and review the INSTALL and README files
63. cd percona-server-5.7.18-14
65.配置软件:
-DBUILD_CONFIG=mysql_release -DFEATURE_SET=community
-DWITH_EMBEDDED_SERVER=OFF
69. make
70. Install the Software:
3. Exercise
(1) Answer the question in Part 2 (Tutorial) the 8th problem. “Why do you
行为(提示:TTY 列)”
(3) 每个终端只会显示到链接到当前的终端的进程。所以看不到,要见到这个
sleep 要用 ps -e
(2) Answer the question in Part 2 (Tutorial) the 19 th problem. (Exercise 2) What
(4) Answer the question in Part 2 (Tutorial) the 28th problem, (Exercise 5) What
(6) 命名 2 个重新启动系统的命令。
(7) How would you command the system to shutdown completely in 20 minutes, and to
display a message to all users saying “going down for system maintenance”?
(https://www.ostechnix.com/check-runlevel-linux/)
你目前的运行级别是什么?
什么命令会将您切换到运行级别 3?
运行级别 3 和 5 之间的主要区别是什么?
什么样的文件是/etc/rc.d/rc.local?
(13) (optional) What link in the /etc/rc.d/rc5.d directory ensures that rc.local is run?
(16) What does the number following the K or S in a filename in /etc/rc.d/rc3.d/ indicate?
[3] 每周一运行/root/ping.bash,周二中午运行
[8] running /root/ping.bash every day from the 5th to the 12th of every month, at 4 AM
(19) Install all available software updates for your system. What command did you use?
(19) 为您的系统安装所有可用的软件更新。你用了什么命令?