diff options
| author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-12-31 12:50:27 +0100 |
|---|---|---|
| committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-12-31 12:50:27 +0100 |
| commit | 44fb488f8a6e2d1dcbb7e119a8acc08d6dfd4ef8 (patch) | |
| tree | 9fea8b8aa052f3cc8b7f775281c73b1b410d92f2 /examples | |
| parent | db639005249cc33fd04533c6222c4d6114439103 (diff) | |
| download | psutil-44fb488f8a6e2d1dcbb7e119a8acc08d6dfd4ef8.tar.gz | |
turn process properties into methods for consistency. this is the most destruptive change.
Diffstat (limited to 'examples')
| -rwxr-xr-x | examples/iotop.py | 6 | ||||
| -rwxr-xr-x | examples/killall.py | 2 | ||||
| -rwxr-xr-x | examples/netstat.py | 2 | ||||
| -rwxr-xr-x | examples/pmap.py | 2 | ||||
| -rwxr-xr-x | examples/process_detail.py | 18 |
5 files changed, 17 insertions, 13 deletions
diff --git a/examples/iotop.py b/examples/iotop.py index 0222790d..06f8d2ac 100755 --- a/examples/iotop.py +++ b/examples/iotop.py @@ -97,10 +97,10 @@ def poll(interval): for p in procs[:]: try: p._after = p.io_counters() - p._cmdline = ' '.join(p.cmdline) + p._cmdline = ' '.join(p.cmdline()) if not p._cmdline: - p._cmdline = p.name - p._username = p.username + p._cmdline = p.name() + p._username = p.username() except psutil.NoSuchProcess: procs.remove(p) disks_after = psutil.disk_io_counters() diff --git a/examples/killall.py b/examples/killall.py index b00b088c..b548e7bc 100755 --- a/examples/killall.py +++ b/examples/killall.py @@ -21,7 +21,7 @@ def main(): killed = [] for proc in psutil.process_iter(): - if proc.name == NAME and proc.pid != os.getpid(): + if proc.name() == NAME and proc.pid != os.getpid(): proc.kill() killed.append(proc.pid) if not killed: diff --git a/examples/netstat.py b/examples/netstat.py index 71f43232..dabb4f89 100755 --- a/examples/netstat.py +++ b/examples/netstat.py @@ -32,7 +32,7 @@ def main(): for p in psutil.process_iter(): name = '?' try: - name = p.name + name = p.name() cons = p.connections(kind='inet') except psutil.AccessDenied: print_(templ % (AD, AD, AD, AD, p.pid, name)) diff --git a/examples/pmap.py b/examples/pmap.py index 8fc5c4c7..7d769887 100755 --- a/examples/pmap.py +++ b/examples/pmap.py @@ -19,7 +19,7 @@ def main(): if len(sys.argv) != 2: sys.exit('usage: pmap pid') p = psutil.Process(int(sys.argv[1])) - print_("pid=%s, name=%s" % (p.pid, p.name)) + print_("pid=%s, name=%s" % (p.pid, p.name())) templ = "%-16s %10s %-7s %s" print_(templ % ("Address", "RSS", "Mode", "Mapping")) total_rss = 0 diff --git a/examples/process_detail.py b/examples/process_detail.py index 26ca6259..965e4262 100755 --- a/examples/process_detail.py +++ b/examples/process_detail.py @@ -18,6 +18,9 @@ import sys import psutil +POSIX = os.name == 'posix' + + def convert_bytes(n): symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') prefix = {} @@ -31,7 +34,7 @@ def convert_bytes(n): def print_(a, b): - if sys.stdout.isatty() and os.name == 'posix': + if sys.stdout.isatty() and POSIX: fmt = '\x1b[1;32m%-17s\x1b[0m %s' % (a, b) else: fmt = '%-15s %s' % (a, b) @@ -49,8 +52,9 @@ def run(pid): sys.exit(str(sys.exc_info()[1])) try: - if p.parent: - parent = '(%s)' % p.parent.name + parent = p.parent() + if parent: + parent = '(%s)' % parent.name() else: parent = '' except psutil.Error: @@ -71,11 +75,11 @@ def run(pid): print_('cmdline', ' '.join(pinfo['cmdline'])) print_('started', started) print_('user', pinfo['username']) - if os.name == 'posix' and pinfo['uids'] and pinfo['gids']: + if POSIX and pinfo['uids'] and pinfo['gids']: print_('uids', 'real=%s, effective=%s, saved=%s' % pinfo['uids']) - if os.name == 'posix' and pinfo['gids']: + if POSIX and pinfo['gids']: print_('gids', 'real=%s, effective=%s, saved=%s' % pinfo['gids']) - if os.name == 'posix': + if POSIX: print_('terminal', pinfo['terminal'] or '') if hasattr(p, 'getcwd'): print_('cwd', pinfo['cwd']) @@ -94,7 +98,7 @@ def run(pid): if children: print_('children', '') for child in children: - print_('', 'pid=%s name=%s' % (child.pid, child.name)) + print_('', 'pid=%s name=%s' % (child.pid, child.name())) if pinfo['open_files'] != ACCESS_DENIED: print_('open files', '') |
