EDA365电子论坛网

标题: Linux查看进程的所有子进程和线程 [打印本页]

作者: thinkfunny    时间: 2020-3-4 10:46
标题: Linux查看进程的所有子进程和线程
得到进程的pid:0 ?0 H( B+ M! S& B$ i
ps -ef | grep process_name | grep -v "grep" | awk '{print $2}'

% g: o- f3 m+ J% o( m, G5 ~
查看进程的所有线程$ N  i9 k" N- x% ]& t0 ^/ `
# ps mp 6648 -o THREAD,tid6 n2 O" j$ s" T  ^* r' ]$ F
USER %CPU PRI SCNT WCHAN USER SYSTEM TID
$ A% f# ^/ Q5 _' ^' j  droot 0.0 - - - - - -
( t: ^* o+ O+ aroot 0.0 24 - - - - 6648" i$ Q2 V2 M% u. Y
root 0.0 21 - - - - 66506 s& J( K. x1 O, i
root 1.0 24 - - - - 14214
5 S7 D: h. S9 L7 n: e7 g" ~6 wroot 0.0 23 - futex_ - - 142161 B+ ?+ M3 l  B) A) h' l
root 0.0 22 - 184466 - - 15374
9 K/ y" `& f. }$ U+ j* Sroot 0.0 23 - 184466 - - 15376
' n* J0 o' v9 m( O- f6 c1 |root 0.0 23 - 184466 - - 15378
/ Z4 L/ @7 _5 d2 v& t) }2 }root 0.0 23 - 184466 - - 153807 S+ u2 R2 C9 I5 L" r$ }
root 0.0 23 - 184466 - - 15392: e6 W: O" b# X2 f
root 0.0 23 - 184466 - - 15394
  W$ R8 V, H% lroot 0.0 23 - 184466 - - 15398

/ l2 d- u4 c; a* Q; l: M) ]
查看所有子进程:; q# K1 O! L) M$ |- ~8 @  e
# pstree -p 6648' s6 {* n% H  W) I3 x4 W, @
agent_executor(6648)─┬─tar(15601)───gzip(15607)
0 ?: m$ ]9 `1 y, f8 S0 T0 x├─{agent_executor}(6650)/ Q0 O! E3 M# @4 W) c
├─{agent_executor}(14214)
0 t) n! `9 C# q1 ~8 ^, B├─{agent_executor}(14216)5 b; k3 W9 Y" c  `
├─{agent_executor}(15374)
& L) o& W" z; ^├─{agent_executor}(15376)3 b3 V7 r& N. k' I" G& H1 X6 \
├─{agent_executor}(15378)
  D# ^5 u# I- f8 M├─{agent_executor}(15380), f8 E, S/ V, U4 y. D8 |4 |
├─{agent_executor}(15392)0 w, q. |; G$ G- z9 t: ^
├─{agent_executor}(15394)3 U, z3 h; W& R( t
└─{agent_executor}(15398)

) d8 |, ^& O5 s/ o: ?) ~6 [
查看/proc/pid/status可以看到一些进程的当前状态:
Name: bash
1 r8 |6 c1 w1 E* [State: S (sleeping)0 E$ @/ ]( G, W* C5 r6 b
SleepAVG: 98%
$ Z3 @3 A/ P+ I' @' A5 _Tgid: 11237  U, K: a: j9 m! p8 u% K
Pid: 11237
8 q- Y8 |2 a) \! I5 jPPid: 11235
# I6 d- b( u/ n% @( [8 u2 K# x) ^TracerPid: 0
3 D9 W: r/ H) s4 H- V* Y# p1 LUid: 0 0 0 0: R. g/ V: P3 l
Gid: 0 0 0 0
2 U5 a+ J. K6 N) i% CFDSize: 256' w  O. j- _( B
Groups: 0 1 2 3 4 6 10
( C, h  v0 }+ ]$ M* b3 U% ?: kVmPeak: 66260 kB
& P7 V' o- D4 \! h3 C7 gVmSize: 66228 kB
+ u% _4 Y5 b5 O0 D# @( T7 ]7 o5 `VmLck: 0 kB
" X+ i$ B/ Y* P: _6 mVmHWM: 1684 kB1 {3 t# l  p: c! B; L
VmRSS: 1684 kB
* C+ ^0 j* V1 @! S5 X1 X' s; ZVmData: 456 kB
1 s+ R5 k7 X+ hVmStk: 88 kB
: U% |& z" G) ^  P3 f& N3 a" eVmExe: 712 kB& z8 I% f: e7 h* K3 H4 S8 A
VmLib: 1508 kB
' _6 m: x7 n1 t; nVmPTE: 68 kB
! }( n' D( V# H7 @+ O% L! CStaBrk: 008c3000 kB5 Q: j+ }0 F( r. B- v
Brk: 011b1000 kB
% Q1 t& s$ R/ Q! ]: GStaStk: 7fff8b728170 kB$ Q( U7 L+ d$ j/ Y$ h7 w# u8 R
Threads: 1$ U  {  m7 P$ w* Z  h
SigQ: 1/30222+ R8 {% \$ _' ~+ t9 s- C
SigPnd: 0000000000000000
- q8 Q' A1 P+ ~. _ShdPnd: 0000000000000000
; C( J3 A2 H6 O% k+ n6 \SigBlk: 0000000000010000% b, v& @. G2 F3 k6 j
SigIgn: 0000000000384004" J% D, x! g" x! l9 _* B
SigCgt: 000000004b813efb% `/ [: H! Q( W; T
CapInh: 0000000000000000! }8 p% e' F  m% C8 O1 N9 |
CapPrm: 00000000fffffeff
2 n0 N2 [) C0 O7 V% O( {CapEff: 00000000fffffeff
0 T! g! @7 k/ s( ]* }& uCpus_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000003) p% Y8 i; i- C0 S: B& S
Mems_allowed: 1

3 H0 m, Q6 ^7 \! Q8 m9 Z+ [  i- K
作者: xixihahaheihei    时间: 2020-3-4 17:35
Linux查看进程的所有子进程和线程




欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/) Powered by Discuz! X3.2