Mik*_*kov 8 process ionice nice
lb build
可以构建实时系统映像,并且在构建映像时会调用许多进程。如果我按如下方式启动它:
# nice -n 19 ionice -n 7 -c 3 lb build
Run Code Online (Sandbox Code Playgroud)
所有子进程都获得相同的好级别:
PID USER IORR IOWR IO IO PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
26196 morfik 0 0 0 B4 20 0 23888 672 668 S 0.0 0.1 0:00.24 ? ?? -bash
30926 root 0 0 0 B4 20 0 53668 536 536 S 0.0 0.1 0:00.02 ? ? ?? su -
31008 root 0 0 0 B4 20 0 34656 6260 1144 S 0.0 0.6 0:02.60 ? ? ?? -su
11784 root 0 0 0 ?? 39 19 4496 796 524 S 0.0 0.1 0:00.01 ? ? ?? /bin/sh /usr/lib/live/build/build
11797 root 0 0 0 ?? 39 19 4328 612 512 S 0.0 0.1 0:00.00 ? ? ?? /bin/sh ./auto/build
11806 root 0 0 0 ?? 39 19 7028 604 504 S 0.0 0.1 0:00.00 ? ? ?? tee build.log
11798 root 0 0 0 ?? 39 19 4496 824 532 S 0.0 0.1 0:00.01 ? ? ?? /bin/sh /usr/lib/live/build/build noauto
11915 root 0 0 0 ?? 39 19 4496 836 544 S 0.0 0.1 0:00.01 ? ? ?? /bin/sh /usr/lib/live/build/bootstrap
12753 root 0 0 0 ?? 39 19 4496 856 548 S 0.0 0.1 0:00.02 ? ? ?? /bin/sh /usr/lib/live/build/bootstra
12867 root 0 0 0 ?? 39 19 62980 3508 2132 S 11.2 0.3 0:07.00 ? ? ?? aptitude --assume-yes update
12943 root 0 0 0 ?? 39 19 24296 1916 1568 S 0.0 0.2 0:00.14 ? ? ?? /usr/lib/apt/methods/xz
12927 root 0 0 0 ?? 39 19 53280 30688 30172 R 86.5 3.0 0:28.65 ? ? ?? /usr/lib/apt/methods/rred
12891 root 0 0 0 ?? 39 19 24304 1784 1440 S 0.0 0.2 0:00.00 ? ? ?? /usr/lib/apt/methods/gpgv
12889 root 0 0 0 ?? 39 19 24292 1624 1384 S 0.0 0.2 0:00.00 ? ? ?? /usr/lib/apt/methods/copy
12887 root 0 0 0 ?? 39 19 32860 1956 1560 S 0.0 0.2 0:00.17 ? ? ?? /usr/lib/apt/methods/http
12886 root 0 0 0 ?? 39 19 24292 1696 1444 S 0.0 0.2 0:00.00 ? ? ?? /usr/lib/apt/methods/fil
Run Code Online (Sandbox Code Playgroud)
但我忘记添加这个nice -n 19 ionice -n 7 -c 3
并运行了lb build
。所以,我尝试renice
了父进程:
# renice -n 19 -p 6187
Run Code Online (Sandbox Code Playgroud)
但这并不妨碍其他进程。所以,它看起来像这样:
26196 morfik 0 0 0 B4 20 0 23888 668 664 S 0.0 0.1 0:00.24 ? ?? -bash
30926 root 0 0 0 B4 20 0 53668 528 528 S 0.0 0.1 0:00.02 ? ? ?? su -
31008 root 0 0 0 B4 20 0 34656 5952 1224 S 0.0 0.6 0:02.62 ? ? ?? -su
6187 root 0 0 0 B7 39 19 4496 800 524 S 0.0 0.1 0:00.00 ? ? ?? /bin/sh /usr/lib/live/build/build
6349 root 0 0 0 B4 20 0 4328 612 512 S 0.0 0.1 0:00.00 ? ? ?? /bin/sh ./auto/build
6351 root 0 0 0 B4 20 0 7028 592 488 S 0.0 0.1 0:00.00 ? ? ?? tee build.log
6350 root 0 0 0 B4 20 0 4496 828 532 S 0.0 0.1 0:00.01 ? ? ?? /bin/sh /usr/lib/live/build/build noauto
6445 root 0 0 0 B4 20 0 4496 840 548 S 0.0 0.1 0:00.00 ? ? ?? /bin/sh /usr/lib/live/build/bootstrap
7580 root 0 0 0 B4 20 0 4496 856 552 S 0.0 0.1 0:00.02 ? ? ?? /bin/sh /usr/lib/live/build/bootstra
7692 root 0 0 0 B4 20 0 62924 5236 3848 S 15.5 0.5 0:03.78 ? ? ?? aptitude --assume-yes update
7932 root 0 0 0 B4 20 0 54776 16480 15916 R 84.1 1.6 0:16.60 ? ? ?? /usr/lib/apt/methods/rred
7912 root 0 0 0 B4 20 0 24296 2036 1648 S 0.0 0.2 0:01.62 ? ? ?? /usr/lib/apt/methods/gzip
7733 root 0 0 0 B4 20 0 27948 5552 1632 S 0.0 0.5 0:02.85 ? ? ?? /usr/lib/apt/methods/bzip2
7711 root 0 0 0 B4 20 0 24304 1780 1436 S 0.0 0.2 0:00.00 ? ? ?? /usr/lib/apt/methods/gpgv
7709 root 0 0 0 B4 20 0 30800 2200 1812 S 0.0 0.2 0:01.01 ? ? ?? /usr/lib/apt/methods/http
Run Code Online (Sandbox Code Playgroud)
我可以手动重新启动所有流程,但它们正在发生变化。
编辑#1
以下命令:
# nice -n 19 ionice -n 7 -c 3 lb build
Run Code Online (Sandbox Code Playgroud)
还设置:
ionice - 设置或获取进程 io 调度类和优先级。...
-c, --class 调度类名或编号 0:无,1:实时,2:尽力而为,3:空闲
-n, --classdata 调度类数据 0-7 用于实时和尽力而为的类
如何设置-c
和-n
选择ionice
进程?
slm*_*slm 10
由于所有子进程仍然是会话 ID(sess
在ps
输出中)的一部分,我们可以使用以下命令利用这一事实:
$ parent=6187
$ ps -eo sess:1=,pid:1= |sed -n "s/^$parent //p"
Run Code Online (Sandbox Code Playgroud)
这应该会返回给我们所有从 产生的子进程的进程 ID lb load
。我们也可以pgrep
使用-s
switch直接从 获取它。
$ pgrep -s $parent
Run Code Online (Sandbox Code Playgroud)
然后我们可以renice
像这样:
$ renice $(pgrep -s $parent)
Run Code Online (Sandbox Code Playgroud)
这是一个人为的例子,希望能说明这一切是如何工作的。我们从一个 shell 开始,“PID=10515”。
1.确认会话ID$ ps -j
PID PGID SID TTY TIME CMD
10515 10515 10515 pts/8 00:00:00 bash
30781 30781 10515 pts/8 00:00:00 ps
Run Code Online (Sandbox Code Playgroud)
2. 假工作
然后我们开始一些我们忘记的假工作renice
。
$ sleep 10000 &
$ sleep 10000 &
Run Code Online (Sandbox Code Playgroud)
我们确认它们在我们的 shell 的会话 ID ( SID
) 下。
$ ps -j
PID PGID SID TTY TIME CMD
10515 10515 10515 pts/8 00:00:00 bash
31107 31107 10515 pts/8 00:00:00 sleep
31111 31111 10515 pts/8 00:00:00 sleep
31140 31140 10515 pts/8 00:00:00 ps
Run Code Online (Sandbox Code Playgroud)
3. 获取与 SID 关联的 PID
我们可以得到所有进程的列表,其SID
值为 10515。
$ pgrep -s 10515
10515
31107
31111
Run Code Online (Sandbox Code Playgroud)
4.确认当前nice
目前大家的nice水平是多少?使用此命令检查:
$ ps -eo sess:1=,pid:1=,nice:1= | grep [1]0515
10515 10515 0
10515 31107 0
10515 31111 0
10515 31354 0
10515 31355 0
Run Code Online (Sandbox Code Playgroud)
5.更改所有SID后代的nice
好的,所以每个人都nice
在 0,让我们改变它。
$ renice $(pgrep -s 10515)
31107 (process ID) old priority 0, new priority 19
31111 (process ID) old priority 0, new priority 19
Run Code Online (Sandbox Code Playgroud)
6. 确认
检查我们的工作:
$ ps -eo sess:1=,pid:1=,nice:1= | grep [1]0515
10515 10515 0
10515 31107 19
10515 31111 19
10515 31426 0
10515 31427 0
Run Code Online (Sandbox Code Playgroud)
PID 31107 和 31111 是我们的睡眠过程,我们只是将它们的 nice 值批量更改为 19,仅包含有关SID
它们关联内容的信息。
ps
如果你真的很偏执,你也可以检查输出:
$ ps -eaf | grep -E "31107|31111"
saml 31107 10515 0 22:30 pts/8 00:00:00 sleep 10000
saml 31111 10515 0 22:30 pts/8 00:00:00 sleep 10000
saml 31531 10515 0 22:35 pts/8 00:00:00 grep --color=auto -E 31107|31111
Run Code Online (Sandbox Code Playgroud)
ionice
如果您试图控制进程的 I/O 优先级以及它们的良好级别,您应该能够将上面的命令示例更改为如下所示:
$ renice -n 19 $(pgrep -s $parent)
$ ionice -c 3 -p $(pgrep -s $parent)
Run Code Online (Sandbox Code Playgroud)
如果您查看手册页,ionice
则无法-c 3
与-n
.
-c, --class class
Specify the name or number of the scheduling class to use; 0 for
none, 1 for realtime, 2 for best-effort, 3 for idle.
-n, --classdata level
Specify the scheduling class data. This only has an effect if
the class accepts an argument. For realtime and best-effort, 0-7
are valid data (priority levels).
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6629 次 |
最近记录: |