mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
crit: The 'ps' explorer
Shows process tree from image. The output is like
PID PGID SID COMM
1 1 1 session00
4 4 4 session00
7 7 7 session00
8 4 4 session00
11 11 11 session00
12 4 4 session00
13 13 13 session00
14 14 14 session00
15 4 4 session00
6 4 4 session00
10 9 9 session00
(the above is for session00 test).
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Appreciated-by: avagin@openvz.org
This commit is contained in:
parent
075c1c9f08
commit
022baf868b
1 changed files with 40 additions and 2 deletions
42
crit
42
crit
|
|
@ -2,6 +2,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
import pycriu
|
import pycriu
|
||||||
|
|
||||||
|
|
@ -52,7 +53,44 @@ def info(opts):
|
||||||
# Explorers
|
# Explorers
|
||||||
#
|
#
|
||||||
|
|
||||||
explorers = { }
|
class ps_item:
|
||||||
|
def __init__(self, p, core):
|
||||||
|
self.pid = p['pid']
|
||||||
|
self.ppid = p['ppid']
|
||||||
|
self.p = p
|
||||||
|
self.core = core
|
||||||
|
self.kids = []
|
||||||
|
|
||||||
|
def show_ps(p, opts, depth = 0):
|
||||||
|
print "%7d%7d%7d %s%s" % (p.pid, p.p['pgid'], p.p['sid'],
|
||||||
|
' ' * (4 * depth), p.core['tc']['comm'])
|
||||||
|
for kid in p.kids:
|
||||||
|
show_ps(kid, opts, depth + 1)
|
||||||
|
|
||||||
|
def explore_ps(opts):
|
||||||
|
pss = { }
|
||||||
|
ps_img = pycriu.images.load(dinf(opts, 'pstree.img'))
|
||||||
|
for p in ps_img['entries']:
|
||||||
|
core = pycriu.images.load(dinf(opts, 'core-%d.img' % p['pid']))
|
||||||
|
ps = ps_item(p, core['entries'][0])
|
||||||
|
pss[ps.pid] = ps
|
||||||
|
|
||||||
|
# Build tree
|
||||||
|
psr = None
|
||||||
|
for pid in pss:
|
||||||
|
p = pss[pid]
|
||||||
|
if p.ppid == 0:
|
||||||
|
psr = p
|
||||||
|
continue
|
||||||
|
|
||||||
|
pp = pss[p.ppid]
|
||||||
|
pp.kids.append(p)
|
||||||
|
|
||||||
|
print "%7s%7s%7s %s" % ('PID', 'PGID', 'SID', 'COMM')
|
||||||
|
show_ps(psr, opts)
|
||||||
|
|
||||||
|
|
||||||
|
explorers = { 'ps': explore_ps }
|
||||||
|
|
||||||
def explore(opts):
|
def explore(opts):
|
||||||
explorers[opts['what']](opts)
|
explorers[opts['what']](opts)
|
||||||
|
|
@ -98,7 +136,7 @@ def main():
|
||||||
# Explore
|
# Explore
|
||||||
x_parser = subparsers.add_parser('x', help = 'explore image dir')
|
x_parser = subparsers.add_parser('x', help = 'explore image dir')
|
||||||
x_parser.add_argument('dir')
|
x_parser.add_argument('dir')
|
||||||
x_parser.add_argument('what', choices = [ ])
|
x_parser.add_argument('what', choices = [ 'ps' ])
|
||||||
x_parser.set_defaults(func=explore)
|
x_parser.set_defaults(func=explore)
|
||||||
|
|
||||||
# Show
|
# Show
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue