草庐IT

android - proc/[pid]/stat 中的值是什么意思?

coder 2023-06-22 原文

我试图开发一个应用程序来获取每个应用程序的 CPU 使用率,并在消耗大量 CPU 时终止应用程序。但我不知道该怎么做。

我已阅读 this post并看过this answer .所以我查看了 proc/[pid]/stat。有很多数值,但我不明白哪个值代表什么。

谁能解释一下 proc/[pid]/stat.. 中值的含义?

最佳答案

来自 man proc(5) :

   /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.

          The fields, in order, with their proper scanf(3) format speci‐
          fiers, are listed below.  Whether or not certain of these
          fields display valid information is governed by a ptrace
          access mode PTRACE_MODE_READ_FSCREDS | PTRACE_MODE_NOAUDIT
          check (refer to ptrace(2)).  If the check denies access, then
          the field value is displayed as 0.  The affected fields are
          indicated with the marking [PT].

          (1) pid  %d
                    The process ID.

          (2) comm  %s
                    The filename of the executable, in parentheses.
                    This is visible whether or not the executable is
                    swapped out.

          (3) state  %c
                    One of the following characters, indicating process
                    state:

                    R  Running

                    S  Sleeping in an interruptible wait

                    D  Waiting in uninterruptible disk sleep

                    Z  Zombie

                    T  Stopped (on a signal) or (before Linux 2.6.33)
                       trace stopped

                    t  Tracing stop (Linux 2.6.33 onward)

                    W  Paging (only before Linux 2.6.0)

                    X  Dead (from Linux 2.6.0 onward)

                    x  Dead (Linux 2.6.33 to 3.13 only)

                    K  Wakekill (Linux 2.6.33 to 3.13 only)

                    W  Waking (Linux 2.6.33 to 3.13 only)

                    P  Parked (Linux 3.9 to 3.13 only)

          (4) ppid  %d
                    The PID of the parent of this process.

          (5) pgrp  %d
                    The process group ID of the process.

          (6) session  %d
                    The session ID of the process.

          (7) tty_nr  %d
                    The controlling terminal of the process.  (The minor
                    device number is contained in the combination of
                    bits 31 to 20 and 7 to 0; the major device number is
                    in bits 15 to 8.)

          (8) tpgid  %d
                    The ID of the foreground process group of the con‐
                    trolling terminal of the process.

          (9) flags  %u
                    The kernel flags word of the process.  For bit mean‐
                    ings, see the PF_* defines in the Linux kernel
                    source file include/linux/sched.h.  Details depend
                    on the kernel version.

                    The format for this field was %lu before Linux 2.6.

          (10) minflt  %lu
                    The number of minor faults the process has made
                    which have not required loading a memory page from
                    disk.

          (11) cminflt  %lu
                    The number of minor faults that the process's
                    waited-for children have made.

          (12) majflt  %lu
                    The number of major faults the process has made
                    which have required loading a memory page from disk.

          (13) cmajflt  %lu
                    The number of major faults that the process's
                    waited-for children have made.

          (14) utime  %lu
                    Amount of time that this process has been scheduled
                    in user mode, measured in clock ticks (divide by
                    sysconf(_SC_CLK_TCK)).  This includes guest time,
                    guest_time (time spent running a virtual CPU, see
                    below), so that applications that are not aware of
                    the guest time field do not lose that time from
                    their calculations.

          (15) stime  %lu
                    Amount of time that this process has been scheduled
                    in kernel mode, measured in clock ticks (divide by
                    sysconf(_SC_CLK_TCK)).

          (16) cutime  %ld
                    Amount of time that this process's waited-for chil‐
                    dren have been scheduled in user mode, measured in
                    clock ticks (divide by sysconf(_SC_CLK_TCK)).  (See
                    also times(2).)  This includes guest time,
                    cguest_time (time spent running a virtual CPU, see
                    below).

          (17) cstime  %ld
                    Amount of time that this process's waited-for chil‐
                    dren have been scheduled in kernel mode, measured in
                    clock ticks (divide by sysconf(_SC_CLK_TCK)).

          (18) priority  %ld
                    (Explanation for Linux 2.6) For processes running a
                    real-time scheduling policy (policy below; see
                    sched_setscheduler(2)), this is the negated schedul‐
                    ing priority, minus one; that is, a number in the
                    range -2 to -100, corresponding to real-time priori‐
                    ties 1 to 99.  For processes running under a non-
                    real-time scheduling policy, this is the raw nice
                    value (setpriority(2)) as represented in the kernel.
                    The kernel stores nice values as numbers in the
                    range 0 (high) to 39 (low), corresponding to the
                    user-visible nice range of -20 to 19.

                    Before Linux 2.6, this was a scaled value based on
                    the scheduler weighting given to this process.

          (19) nice  %ld
                    The nice value (see setpriority(2)), a value in the
                    range 19 (low priority) to -20 (high priority).

          (20) num_threads  %ld
                    Number of threads in this process (since Linux 2.6).
                    Before kernel 2.6, this field was hard coded to 0 as
                    a placeholder for an earlier removed field.

          (21) itrealvalue  %ld
                    The time in jiffies before the next SIGALRM is sent
                    to the process due to an interval timer.  Since ker‐
                    nel 2.6.17, this field is no longer maintained, and
                    is hard coded as 0.

          (22) starttime  %llu
                    The time the process started after system boot.  In
                    kernels before Linux 2.6, this value was expressed
                    in jiffies.  Since Linux 2.6, the value is expressed
                    in clock ticks (divide by sysconf(_SC_CLK_TCK)).

                    The format for this field was %lu before Linux 2.6.

          (23) vsize  %lu
                    Virtual memory size in bytes.

          (24) rss  %ld
                    Resident Set Size: number of pages the process has
                    in real memory.  This is just the pages which count
                    toward text, data, or stack space.  This does not
                    include pages which have not been demand-loaded in,
                    or which are swapped out.

          (25) rsslim  %lu
                    Current soft limit in bytes on the rss of the
                    process; see the description of RLIMIT_RSS in
                    getrlimit(2).

          (26) startcode  %lu  [PT]
                    The address above which program text can run.

          (27) endcode  %lu  [PT]
                    The address below which program text can run.

          (28) startstack  %lu  [PT]
                    The address of the start (i.e., bottom) of the
                    stack.

          (29) kstkesp  %lu  [PT]
                    The current value of ESP (stack pointer), as found
                    in the kernel stack page for the process.

          (30) kstkeip  %lu  [PT]
                    The current EIP (instruction pointer).

          (31) signal  %lu
                    The bitmap of pending signals, displayed as a deci‐
                    mal number.  Obsolete, because it does not provide
                    information on real-time signals; use
                    /proc/[pid]/status instead.

          (32) blocked  %lu
                    The bitmap of blocked signals, displayed as a deci‐
                    mal number.  Obsolete, because it does not provide
                    information on real-time signals; use
                    /proc/[pid]/status instead.

          (33) sigignore  %lu
                    The bitmap of ignored signals, displayed as a deci‐
                    mal number.  Obsolete, because it does not provide
                    information on real-time signals; use
                    /proc/[pid]/status instead.

          (34) sigcatch  %lu
                    The bitmap of caught signals, displayed as a decimal
                    number.  Obsolete, because it does not provide
                    information on real-time signals; use
                    /proc/[pid]/status instead.

          (35) wchan  %lu  [PT]
                    This is the "channel" in which the process is wait‐
                    ing.  It is the address of a location in the kernel
                    where the process is sleeping.  The corresponding
                    symbolic name can be found in /proc/[pid]/wchan.

          (36) nswap  %lu
                    Number of pages swapped (not maintained).

          (37) cnswap  %lu
                    Cumulative nswap for child processes (not main‐
                    tained).

          (38) exit_signal  %d  (since Linux 2.1.22)
                    Signal to be sent to parent when we die.

          (39) processor  %d  (since Linux 2.2.8)
                    CPU number last executed on.

          (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.

                    The format for this field was %lu before Linux
                    2.6.22.

          (42) delayacct_blkio_ticks  %llu  (since Linux 2.6.18)
                    Aggregated block I/O delays, measured in clock ticks
                    (centiseconds).

          (43) guest_time  %lu  (since Linux 2.6.24)
                    Guest time of the process (time spent running a vir‐
                    tual CPU for a guest operating system), measured in
                    clock ticks (divide by sysconf(_SC_CLK_TCK)).

          (44) cguest_time  %ld  (since Linux 2.6.24)
                    Guest time of the process's children, measured in
                    clock ticks (divide by sysconf(_SC_CLK_TCK)).

          (45) start_data  %lu  (since Linux 3.3)  [PT]
                    Address above which program initialized and unini‐
                    tialized (BSS) data are placed.

          (46) end_data  %lu  (since Linux 3.3)  [PT]
                    Address below which program initialized and unini‐
                    tialized (BSS) data are placed.

          (47) start_brk  %lu  (since Linux 3.3)  [PT]
                    Address above which program heap can be expanded
                    with brk(2).

          (48) arg_start  %lu  (since Linux 3.5)  [PT]
                    Address above which program command-line arguments
                    (argv) are placed.

          (49) arg_end  %lu  (since Linux 3.5)  [PT]
                    Address below program command-line arguments (argv)
                    are placed.

          (50) env_start  %lu  (since Linux 3.5)  [PT]
                    Address above which program environment is placed.

          (51) env_end  %lu  (since Linux 3.5)  [PT]
                    Address below which program environment is placed.

          (52) exit_code  %d  (since Linux 3.5)  [PT]
                    The thread's exit status in the form reported by
                    waitpid(2).

关于android - proc/[pid]/stat 中的值是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39066998/

有关android - proc/[pid]/stat 中的值是什么意思?的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  3. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时

  4. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  5. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题

  6. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  7. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  8. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  9. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  10. ruby - 为什么 4.1%2 使用 Ruby 返回 0.0999999999999996?但是 4.2%2==0.2 - 2

    为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返

随机推荐