如何查看`ps`输出以外的进程调度策略

问题描述 投票:0回答:3

我使用的是busybox版本的linux,想要检查进程调度策略。

PS
输出仅显示
PID USER       VSZ STAT COMMAND
,无论
PS
命令给出的任何选项如何。还有其他方法可以查看进程调度策略吗?

提前致谢!

linux shell busybox
3个回答
5
投票

您可以通过查看

/proc/pocess_id/sched
找到流程的调度信息。

例如:

awk '/policy/ {print $NF}' /proc/25/sched

会给你处理的保单编号

25

有关保单号码的更多信息,您可以查看

man sched_setscheduler

Scheduling Policies:
    ...
   For  threads scheduled under one of the normal scheduling policies
   (SCHED_OTHER, SCHED_IDLE, SCHED_BATCH), sched_priority is not used
   in scheduling decisions (it must be specified as 0).

   Processes scheduled under one of the real-time policies
   (SCHED_FIFO, SCHED_RR) have a sched_priority value in the range 1
   (low)  to  99  (high).  (As the numbers imply, real-time threads
   always have higher priority than normal threads.)  Note well:
   POSIX.1-2001 requires an implementation to support only a minimum
   32 distinct priority levels for the real-time policies, and some
   systems supply  just  this  minimum.   Portable  programs should
   use sched_get_priority_min(2) and sched_get_priority_max(2) to
   find the range of priorities supported for a particular policy.

0
投票

如果您的 BusyBox 安装包含

chrt
,请获取例如PID 4242:

chrt -p 4242
# prints:
pid 4242s current scheduling policy: SCHED_OTHER
pid 4242s current scheduling priority: 0

如果您的 BusyBox 缺少

chrt
,您将不得不退回到 proc 文件系统。在我的嵌入式设备上,缺少
/proc/PID/sched
,但存在
/proc/PID/stat
。 使用
cut
获取策略值,该值位于字段 41:

cat /proc/4242/stat | cut -d ' ' -f 41
# prints:
0

0
表示 SCHED_NORMAL,请参阅
include/uapi/linux/sched.h
:

#define SCHED_NORMAL            0
#define SCHED_FIFO              1
#define SCHED_RR                2
#define SCHED_BATCH             3

stat
文件包含许多有趣的字段,例如nice value (19)、rt_priority (40) 和policy (41)。检查
man 5 proc
了解所有值。

 /proc/pid/stat
              Status information about the process.  This is used by
              ps(1).  It is defined in the kernel source file
              fs/proc/array.c.
[...]
              (40) rt_priority  %u  (since Linux 2.5.19)
                     Real-time scheduling priority, a number in the
                     range 1 to 99 for processes scheduled under a real-
                     time policy, or 0, for non-real-time processes (see
                     sched_setscheduler(2)).

              (41) policy  %u  (since Linux 2.5.19)
                     Scheduling policy (see sched_setscheduler(2)).
                     Decode using the SCHED_* constants in
                     linux/sched.h.

-2
投票

要了解您的内核配置了哪个 IO 调度程序,请输入:

cat /proc/config.gz |grep CONFIG_DEFAULT_IOSCHED
© www.soinside.com 2019 - 2024. All rights reserved.