当前位置: 代码迷 >> 综合 >> android oreo 中adb shell中的ps命令需要加参数ps -A
  详细解决方案

android oreo 中adb shell中的ps命令需要加参数ps -A

热度:11   发布时间:2023-12-06 13:08:00.0

更新了android oreo后发现在adb shell中执行ps命令只得到了很少的信息:

msm8937_32:/ # ps
USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
root          4285  1516    4632   1544 sigsuspend   add6067c S sh
root          5421  4285    5628   1560 0            a93e53b4 R ps

查看ps命令的bin文件,发现其指向了toybox而之前版本指向的是toolbox。

msm8937_32:/system/bin # ls -al ps
lrwxr-xr-x 1 root shell 6 2017-09-04 11:22 ps -> toybox


经过查找toybox的使用发现ps的默认参数有变化,需要执行ps -A

msm8937_32:/system/bin # ps -A
USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
root             1     0   14352   2396 SyS_epoll_wait  c0b3c S init
root             2     0       0      0 kthreadd            0 S [kthreadd]
root             3     2       0      0 smpboot_thread_fn   0 S [ksoftirqd/0]
root             5     2       0      0 worker_thread       0 S [kworker/0:0H]
root             7     2       0      0 rcu_gp_kthread      0 S [rcu_preempt]
root             8     2       0      0 rcu_gp_kthread      0 S [rcu_sched]
root             9     2       0      0 rcu_gp_kthread      0 S [rcu_bh]
root            10     2       0      0 rcu_nocb_kthread    0 S [rcuop/0]
root            11     2       0      0 rcu_nocb_kthread    0 S [rcuos/0]
root            12     2       0      0 rcu_nocb_kthread    0 S [rcuob/0]
root            13     2       0      0 smpboot_thread_fn   0 S [rcuc/0]
root            14     2       0      0 rcu_boost_kthread   0 S [rcub/0]
root            15     2       0      0 smpboot_thread_fn   0 S [migration/0]
root            16     2       0      0 __kthread_parkme    0 R [migration/1]
root            17     2       0      0 __kthread_parkme    0 R [rcuc/1]
root            18     2       0      0 __kthread_parkme    0 R [ksoftirqd/1]
root            20     2       0      0 worker_thread       0 S [kworker/1:0H]
root            21     2       0      0 rcu_nocb_kthread    0 S [rcuop/1]
root            22     2       0      0 rcu_nocb_kthread    0 S [rcuos/1]
root            23     2       0      0 rcu_nocb_kthread    0 S [rcuob/1]
root            24     2       0      0 smpboot_thread_fn   0 S [migration/2]
root            25     2       0      0 smpboot_thread_fn   0 S [rcuc/2]

另外ps --help可以发现toybox中的ps命令更为强大了^-^

msm8937_32:/system/bin # ps --help
usage: ps [-AadefLlnwZ] [-gG GROUP,] [-k FIELD,] [-o FIELD,] [-p PID,] [-t TTY,] [-uU USER,]List processes.Which processes to show (selections may be comma separated lists):-A      All processes
-a      Processes with terminals that aren't session leaders
-d      All processes that aren't session leaders
-e      Same as -A
-g      Belonging to GROUPs
-G      Belonging to real GROUPs (before sgid)
-p      PIDs (--pid)
-P      Parent PIDs (--ppid)
-s      In session IDs
-t      Attached to selected TTYs
-T      Show threads
-u      Owned by USERs
-U      Owned by real USERs (before suid)Output modifiers:-k      Sort FIELDs in +increasing or -decreasting order (--sort)
-M      Measure field widths (expanding as necessary)
-n      Show numeric USER and GROUP
-w      Wide output (don't truncate fields)Which FIELDs to show. (Default = -o PID,TTY,TIME,CMD)-f      Full listing (-o USER:12=UID,PID,PPID,C,STIME,TTY,TIME,ARGS=CMD)
-l      Long listing (-o F,S,UID,PID,PPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD)
-o      Output FIELDs instead of defaults, each with optional :size and =title
-O      Add FIELDS to defaults
-Z      Include LABELCommand line -o fields:ARGS     CMDLINE minus initial path     CMD  Command (thread) name (stat[2])CMDLINE  Command line (argv[])          COMM Command filename (/proc/$PID/exe)COMMAND  Command file (/proc/$PID/exe)  NAME Process name (argv[0] of $PID)Process attribute -o FIELDs:ADDR  Instruction pointer               BIT   Is this process 32 or 64 bitsCPU   Which processor running on        ETIME   Elapsed time since PID startF     Flags (1=FORKNOEXEC 4=SUPERPRIV)  GID     Group idGROUP Group name                        LABEL   Security labelMAJFL Major page faults                 MINFL   Minor page faultsNI    Niceness (lower is faster)PCPU  Percentage of CPU time used       PCY     Android scheduling policyPGID  Process Group IDPID   Process ID                        PPID    Parent Process IDPRI   Priority (higher is faster)       PSR     Processor last executed onRGID  Real (before sgid) group ID       RGROUP  Real (before sgid) group nameRSS   Resident Set Size (pages in use)  RTPRIO  Realtime priorityRUID  Real (before suid) user ID        RUSER   Real (before suid) user nameS     Process state:R (running) S (sleeping) D (device I/O) T (stopped)  t (traced)Z (zombie)  X (deader)   x (dead)       K (wakekill) W (waking)SCHED Scheduling policy (0=other, 1=fifo, 2=rr, 3=batch, 4=iso, 5=idle)STAT  Process state (S) plus:< high priority          N low priority L locked memorys session leader         + foreground   l multithreadedSTIME Start time of process in hh:mm (size :19 shows yyyy-mm-dd hh:mm:ss)SZ    Memory Size (4k pages needed to completely swap out process)TCNT  Thread count                      TID     Thread IDTIME  CPU time consumed                 TTY     Controlling terminalUID   User id                           USER    User nameVSZ   Virtual memory size (1k units)    %VSZ    VSZ as % of physical memoryWCHAN What are we waiting in kernel for



  相关解决方案