[CRIU] [PATCH 2/3] crit: The 'ps' explorer
Pavel Emelyanov
xemul at parallels.com
Mon Dec 14 02:20:04 PST 2015
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 at parallels.com>
---
crit | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/crit b/crit
index f054dcf..0b500b2 100755
--- a/crit
+++ b/crit
@@ -2,6 +2,7 @@
import argparse
import sys
import json
+import os
import pycriu
@@ -52,7 +53,44 @@ def info(opts):
# 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):
explorers[opts['what']](opts)
@@ -98,7 +136,7 @@ def main():
# Explore
x_parser = subparsers.add_parser('x', help = 'explore image 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)
# Show
--
1.9.3
More information about the CRIU
mailing list