summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-10-02 22:36:23 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-10-02 22:36:23 +0200
commita6fd47e7223b8c04382446531180c6f4b3cbd0ab (patch)
tree4db9a19fc1e833b4ad1ff2a744f7eaf4a0f312f7 /scripts
parentd46e922af59c78431dbe27d115d063ebab673dc1 (diff)
parent02cb20f395f9727493036717d2242917ba5425b0 (diff)
downloadpsutil-a6fd47e7223b8c04382446531180c6f4b3cbd0ab.tar.gz
Merge branch 'master' into oneshot
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/disk_usage.py1
-rwxr-xr-xscripts/free.py1
-rwxr-xr-xscripts/ifconfig.py83
-rw-r--r--scripts/internal/winmake.py7
-rwxr-xr-xscripts/iotop.py1
-rwxr-xr-xscripts/killall.py4
-rwxr-xr-xscripts/netstat.py1
-rwxr-xr-xscripts/nettop.py1
-rwxr-xr-xscripts/pidof.py1
-rwxr-xr-xscripts/pmap.py1
-rwxr-xr-xscripts/procinfo.py323
-rwxr-xr-xscripts/procsmem.py1
-rwxr-xr-xscripts/ps.py1
-rwxr-xr-xscripts/top.py12
-rwxr-xr-xscripts/who.py1
15 files changed, 320 insertions, 119 deletions
diff --git a/scripts/disk_usage.py b/scripts/disk_usage.py
index 2bb928c0..37f4da0c 100755
--- a/scripts/disk_usage.py
+++ b/scripts/disk_usage.py
@@ -58,5 +58,6 @@ def main():
part.fstype,
part.mountpoint))
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/scripts/free.py b/scripts/free.py
index 897f006f..82e962ff 100755
--- a/scripts/free.py
+++ b/scripts/free.py
@@ -37,5 +37,6 @@ def main():
'',
''))
+
if __name__ == '__main__':
main()
diff --git a/scripts/ifconfig.py b/scripts/ifconfig.py
index 72cc02fe..b823b374 100755
--- a/scripts/ifconfig.py
+++ b/scripts/ifconfig.py
@@ -8,32 +8,39 @@
A clone of 'ifconfig' on UNIX.
$ python scripts/ifconfig.py
-lo (speed=0MB, duplex=?, mtu=65536, up=yes):
- IPv4 address : 127.0.0.1
- broadcast : 127.0.0.1
- netmask : 255.0.0.0
- IPv6 address : ::1
- netmask : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
- MAC address : 00:00:00:00:00:00
- broadcast : 00:00:00:00:00:00
+lo:
+ stats : speed=0MB, duplex=?, mtu=65536, up=yes
+ incoming : bytes=6889336, pkts=84032, errs=0, drops=0
+ outgoing : bytes=6889336, pkts=84032, errs=0, drops=0
+ IPv4 address : 127.0.0.1
+ netmask : 255.0.0.0
+ IPv6 address : ::1
+ netmask : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
+ MAC address : 00:00:00:00:00:00
-wlan0 (speed=0MB, duplex=?, mtu=1500, up=yes):
- IPv4 address : 10.0.3.1
- broadcast : 10.0.3.255
- netmask : 255.255.255.0
- IPv6 address : fe80::3005:adff:fe31:8698
- netmask : ffff:ffff:ffff:ffff::
- MAC address : 32:05:ad:31:86:98
- broadcast : ff:ff:ff:ff:ff:ff
+vboxnet0:
+ stats : speed=10MB, duplex=full, mtu=1500, up=yes
+ incoming : bytes=0, pkts=0, errs=0, drops=0
+ outgoing : bytes=1622766, pkts=9102, errs=0, drops=0
+ IPv4 address : 192.168.33.1
+ broadcast : 192.168.33.255
+ netmask : 255.255.255.0
+ IPv6 address : fe80::800:27ff:fe00:0%vboxnet0
+ netmask : ffff:ffff:ffff:ffff::
+ MAC address : 0a:00:27:00:00:00
+ broadcast : ff:ff:ff:ff:ff:ff
-eth0 (speed=100MB, duplex=full, mtu=1500, up=yes):
- IPv4 address : 192.168.1.2
- broadcast : 192.168.1.255
- netmask : 255.255.255.0
- IPv6 address : fe80::c685:8ff:fe45:641
- netmask : ffff:ffff:ffff:ffff::
- MAC address : c4:85:08:45:06:41
- broadcast : ff:ff:ff:ff:ff:ff
+eth0:
+ stats : speed=0MB, duplex=?, mtu=1500, up=yes
+ incoming : bytes=18905596301, pkts=15178374, errs=0, drops=21
+ outgoing : bytes=1913720087, pkts=9543981, errs=0, drops=0
+ IPv4 address : 10.0.0.3
+ broadcast : 10.255.255.255
+ netmask : 255.0.0.0
+ IPv6 address : fe80::7592:1dcf:bcb7:98d6%wlp3s0
+ netmask : ffff:ffff:ffff:ffff::
+ MAC address : 48:45:20:59:a4:0c
+ broadcast : ff:ff:ff:ff:ff:ff
"""
from __future__ import print_function
@@ -57,22 +64,32 @@ duplex_map = {
def main():
stats = psutil.net_if_stats()
+ io_counters = psutil.net_io_counters(pernic=True)
for nic, addrs in psutil.net_if_addrs().items():
+ print("%s:" % (nic))
if nic in stats:
- print("%s (speed=%sMB, duplex=%s, mtu=%s, up=%s):" % (
- nic, stats[nic].speed, duplex_map[stats[nic].duplex],
- stats[nic].mtu, "yes" if stats[nic].isup else "no"))
- else:
- print("%s:" % (nic))
+ st = stats[nic]
+ print(" stats : ", end='')
+ print("speed=%sMB, duplex=%s, mtu=%s, up=%s" % (
+ st.speed, duplex_map[st.duplex], st.mtu,
+ "yes" if st.isup else "no"))
+ if nic in io_counters:
+ io = io_counters[nic]
+ print(" incoming : ", end='')
+ print("bytes=%s, pkts=%s, errs=%s, drops=%s" % (
+ io.bytes_recv, io.packets_recv, io.errin, io.dropin))
+ print(" outgoing : ", end='')
+ print("bytes=%s, pkts=%s, errs=%s, drops=%s" % (
+ io.bytes_sent, io.packets_sent, io.errout, io.dropout))
for addr in addrs:
- print(" %-8s" % af_map.get(addr.family, addr.family), end="")
+ print(" %-4s" % af_map.get(addr.family, addr.family), end="")
print(" address : %s" % addr.address)
if addr.broadcast:
- print(" broadcast : %s" % addr.broadcast)
+ print(" broadcast : %s" % addr.broadcast)
if addr.netmask:
- print(" netmask : %s" % addr.netmask)
+ print(" netmask : %s" % addr.netmask)
if addr.ptp:
- print(" p2p : %s" % addr.ptp)
+ print(" p2p : %s" % addr.ptp)
print("")
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index 23ccbca2..8351a675 100644
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -258,6 +258,13 @@ def test_platform():
@cmd
+def test_misc():
+ """Run misc tests"""
+ install()
+ sh("%s -m unittest -v psutil.tests.test_misc" % PYTHON)
+
+
+@cmd
def test_by_name():
"""Run test by name"""
try:
diff --git a/scripts/iotop.py b/scripts/iotop.py
index 1a8d8ba5..c0b44568 100755
--- a/scripts/iotop.py
+++ b/scripts/iotop.py
@@ -176,5 +176,6 @@ def main():
except (KeyboardInterrupt, SystemExit):
pass
+
if __name__ == '__main__':
main()
diff --git a/scripts/killall.py b/scripts/killall.py
index b548e7bc..f9cc9201 100755
--- a/scripts/killall.py
+++ b/scripts/killall.py
@@ -29,4 +29,6 @@ def main():
else:
sys.exit(0)
-sys.exit(main())
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/netstat.py b/scripts/netstat.py
index a5e171bc..1426cd76 100755
--- a/scripts/netstat.py
+++ b/scripts/netstat.py
@@ -60,5 +60,6 @@ def main():
proc_names.get(c.pid, '?')[:15],
))
+
if __name__ == '__main__':
main()
diff --git a/scripts/nettop.py b/scripts/nettop.py
index acfa6500..97f80aad 100755
--- a/scripts/nettop.py
+++ b/scripts/nettop.py
@@ -161,5 +161,6 @@ def main():
except (KeyboardInterrupt, SystemExit):
pass
+
if __name__ == '__main__':
main()
diff --git a/scripts/pidof.py b/scripts/pidof.py
index 0db9563e..1c23900f 100755
--- a/scripts/pidof.py
+++ b/scripts/pidof.py
@@ -50,5 +50,6 @@ def main():
if pids:
print(" ".join(pids))
+
if __name__ == '__main__':
main()
diff --git a/scripts/pmap.py b/scripts/pmap.py
index f0d53355..16eebb60 100755
--- a/scripts/pmap.py
+++ b/scripts/pmap.py
@@ -53,5 +53,6 @@ def main():
print("-" * 33)
print(templ % ("Total", str(total_rss / 1024) + 'K', '', ''))
+
if __name__ == '__main__':
main()
diff --git a/scripts/procinfo.py b/scripts/procinfo.py
index 9990086f..c5238b37 100755
--- a/scripts/procinfo.py
+++ b/scripts/procinfo.py
@@ -8,37 +8,111 @@
Print detailed information about a process.
Author: Giampaolo Rodola' <g.rodola@gmail.com>
-$ python scripts/process_detail.py
-pid 820
-name python
-exe /usr/bin/python2.7
-parent 29613 (bash)
-cmdline python scripts/process_detail.py
-started 2014-41-27 03:41
-user giampaolo
-uids real=1000, effective=1000, saved=1000
-gids real=1000, effective=1000, saved=1000
-terminal /dev/pts/17
-cwd /ssd/svn/psutil
-memory 0.1% (resident=10.6M, virtual=58.5M)
-cpu 0.0% (user=0.09, system=0.0)
-status running
-niceness 0
-num threads 1
-I/O bytes-read=0B, bytes-written=0B
-open files
-running threads id=820, user-time=0.09, sys-time=0.0
+$ python scripts/procinfo.py
+pid 4600
+name chrome
+parent 4554 (bash)
+exe /opt/google/chrome/chrome
+cwd /home/giampaolo
+cmdline /opt/google/chrome/chrome
+started 2016-09-19 11:12
+cpu-tspent 27:27.68
+cpu-times user=8914.32, system=3530.59,
+ children_user=1.46, children_system=1.31
+cpu-affinity [0, 1, 2, 3, 4, 5, 6, 7]
+memory rss=520.5M, vms=1.9G, shared=132.6M, text=95.0M, lib=0B,
+ data=816.5M, dirty=0B
+memory % 3.26
+user giampaolo
+uids real=1000, effective=1000, saved=1000
+uids real=1000, effective=1000, saved=1000
+terminal /dev/pts/2
+status sleeping
+nice 0
+ionice class=IOPriority.IOPRIO_CLASS_NONE, value=0
+num-threads 47
+num-fds 379
+I/O read_count=96.6M, write_count=80.7M,
+ read_bytes=293.2M, write_bytes=24.5G
+ctx-switches voluntary=30426463, involuntary=460108
+children PID NAME
+ 4605 cat
+ 4606 cat
+ 4609 chrome
+ 4669 chrome
+open-files PATH
+ /opt/google/chrome/icudtl.dat
+ /opt/google/chrome/snapshot_blob.bin
+ /opt/google/chrome/natives_blob.bin
+ /opt/google/chrome/chrome_100_percent.pak
+ [...]
+connections PROTO LOCAL ADDR REMOTE ADDR STATUS
+ UDP 10.0.0.3:3693 *:* NONE
+ TCP 10.0.0.3:55102 172.217.22.14:443 ESTABLISHED
+ UDP 10.0.0.3:35172 *:* NONE
+ TCP 10.0.0.3:32922 172.217.16.163:443 ESTABLISHED
+ UDP :::5353 *:* NONE
+ UDP 10.0.0.3:59925 *:* NONE
+threads TID USER SYSTEM
+ 11795 0.7 1.35
+ 11796 0.68 1.37
+ 15887 0.74 0.03
+ 19055 0.77 0.01
+ [...]
+ total=47
+res-limits RLIMIT SOFT HARD
+ virtualmem infinity infinity
+ coredumpsize 0 infinity
+ cputime infinity infinity
+ datasize infinity infinity
+ filesize infinity infinity
+ locks infinity infinity
+ memlock 65536 65536
+ msgqueue 819200 819200
+ nice 0 0
+ openfiles 8192 65536
+ maxprocesses 63304 63304
+ rss infinity infinity
+ realtimeprio 0 0
+ rtimesched infinity infinity
+ sigspending 63304 63304
+ stack 8388608 infinity
+mem-maps RSS PATH
+ 381.4M [anon]
+ 62.8M /opt/google/chrome/chrome
+ 15.8M /home/giampaolo/.config/google-chrome/Default/History
+ 6.6M /home/giampaolo/.config/google-chrome/Default/Favicons
+ [...]
"""
+import argparse
import datetime
-import os
import socket
import sys
import psutil
-POSIX = os.name == 'posix'
+ACCESS_DENIED = ''
+NON_VERBOSE_ITERATIONS = 4
+RLIMITS_MAP = {
+ "RLIMIT_AS": "virtualmem",
+ "RLIMIT_CORE": "coredumpsize",
+ "RLIMIT_CPU": "cputime",
+ "RLIMIT_DATA": "datasize",
+ "RLIMIT_FSIZE": "filesize",
+ "RLIMIT_LOCKS": "locks",
+ "RLIMIT_MEMLOCK": "memlock",
+ "RLIMIT_MSGQUEUE": "msgqueue",
+ "RLIMIT_NICE": "nice",
+ "RLIMIT_NOFILE": "openfiles",
+ "RLIMIT_NPROC": "maxprocesses",
+ "RLIMIT_RSS": "rss",
+ "RLIMIT_RTPRIO": "realtimeprio",
+ "RLIMIT_RTTIME": "rtimesched",
+ "RLIMIT_SIGPENDING": "sigspending",
+ "RLIMIT_STACK": "stack",
+}
def convert_bytes(n):
@@ -54,87 +128,117 @@ def convert_bytes(n):
def print_(a, b):
- if sys.stdout.isatty() and POSIX:
- fmt = '\x1b[1;32m%-17s\x1b[0m %s' % (a, b)
+ if sys.stdout.isatty() and psutil.POSIX:
+ fmt = '\x1b[1;32m%-13s\x1b[0m %s' % (a, b)
else:
- fmt = '%-15s %s' % (a, b)
+ fmt = '%-11s %s' % (a, b)
print(fmt)
-def run(pid):
- ACCESS_DENIED = ''
+def str_ntuple(nt, bytes2human=False):
+ if nt == ACCESS_DENIED:
+ return ""
+ if not bytes2human:
+ return ", ".join(["%s=%s" % (x, getattr(nt, x)) for x in nt._fields])
+ else:
+ return ", ".join(["%s=%s" % (x, convert_bytes(getattr(nt, x)))
+ for x in nt._fields])
+
+
+def run(pid, verbose=False):
try:
- p = psutil.Process(pid)
- pinfo = p.as_dict(ad_value=ACCESS_DENIED)
+ proc = psutil.Process(pid)
+ pinfo = proc.as_dict(ad_value=ACCESS_DENIED)
except psutil.NoSuchProcess as err:
sys.exit(str(err))
try:
- parent = p.parent()
+ parent = proc.parent()
if parent:
parent = '(%s)' % parent.name()
else:
parent = ''
except psutil.Error:
parent = ''
- if pinfo['create_time'] != ACCESS_DENIED:
+ if pinfo['create_time']:
started = datetime.datetime.fromtimestamp(
pinfo['create_time']).strftime('%Y-%m-%d %H:%M')
else:
started = ACCESS_DENIED
- io = pinfo.get('io_counters', ACCESS_DENIED)
- if pinfo['memory_info'] != ACCESS_DENIED:
- mem = '%s%% (resident=%s, virtual=%s) ' % (
- round(pinfo['memory_percent'], 1),
- convert_bytes(pinfo['memory_info'].rss),
- convert_bytes(pinfo['memory_info'].vms))
- else:
- mem = ACCESS_DENIED
- children = p.children()
+ children = proc.children()
print_('pid', pinfo['pid'])
print_('name', pinfo['name'])
- print_('exe', pinfo['exe'])
print_('parent', '%s %s' % (pinfo['ppid'], parent))
+ print_('exe', pinfo['exe'])
+ print_('cwd', pinfo['cwd'])
print_('cmdline', ' '.join(pinfo['cmdline']))
print_('started', started)
+
+ cpu_tot_time = datetime.timedelta(seconds=sum(pinfo['cpu_times']))
+ cpu_tot_time = "%s:%s.%s" % (
+ cpu_tot_time.seconds // 60 % 60,
+ str((cpu_tot_time.seconds % 60)).zfill(2),
+ str(cpu_tot_time.microseconds)[:2])
+ print_('cpu-tspent', cpu_tot_time)
+ print_('cpu-times', str_ntuple(pinfo['cpu_times']))
+ if hasattr(proc, "cpu_affinity"):
+ print_("cpu-affinity", pinfo["cpu_affinity"])
+
+ print_('memory', str_ntuple(pinfo['memory_info'], bytes2human=True))
+ print_('memory %', round(pinfo['memory_percent'], 2))
print_('user', pinfo['username'])
- if POSIX and pinfo['uids'] and pinfo['gids']:
- print_('uids', 'real=%s, effective=%s, saved=%s' % pinfo['uids'])
- if POSIX and pinfo['gids']:
- print_('gids', 'real=%s, effective=%s, saved=%s' % pinfo['gids'])
- if POSIX:
+ if psutil.POSIX:
+ print_('uids', str_ntuple(pinfo['uids']))
+ if psutil.POSIX:
+ print_('uids', str_ntuple(pinfo['uids']))
+ if psutil.POSIX:
print_('terminal', pinfo['terminal'] or '')
- print_('cwd', pinfo['cwd'])
- print_('memory', mem)
- print_('cpu', '%s%% (user=%s, system=%s)' % (
- pinfo['cpu_percent'],
- getattr(pinfo['cpu_times'], 'user', '?'),
- getattr(pinfo['cpu_times'], 'system', '?')))
+
print_('status', pinfo['status'])
- print_('niceness', pinfo['nice'])
- print_('num threads', pinfo['num_threads'])
- if io != ACCESS_DENIED:
- print_('I/O', 'bytes-read=%s, bytes-written=%s' % (
- convert_bytes(io.read_bytes),
- convert_bytes(io.write_bytes)))
+ print_('nice', pinfo['nice'])
+ if hasattr(proc, "ionice"):
+ ionice = proc.ionice()
+ if psutil.WINDOWS:
+ print_("ionice", ionice)
+ else:
+ print_("ionice", "class=%s, value=%s" % (
+ str(ionice.ioclass), ionice.value))
+
+ print_('num-threads', pinfo['num_threads'])
+ if psutil.POSIX:
+ print_('num-fds', pinfo['num_fds'])
+ if psutil.WINDOWS:
+ print_('num-handles', pinfo['num_handles'])
+
+ if 'io_counters' in pinfo:
+ print_('I/O', str_ntuple(pinfo['io_counters'], bytes2human=True))
+ print_("ctx-switches", str_ntuple(pinfo['num_ctx_switches']))
if children:
- print_('children', '')
+ template = "%-6s %s"
+ print_("children", template % ("PID", "NAME"))
for child in children:
- print_('', 'pid=%s name=%s' % (child.pid, child.name()))
+ try:
+ print_('', template % (child.pid, child.name()))
+ except psutil.AccessDenied:
+ print_('', template % (child.pid, ""))
+ except psutil.NoSuchProcess:
+ pass
- if pinfo['open_files'] != ACCESS_DENIED and pinfo['open_files']:
- print_('open files', '')
- for file in pinfo['open_files']:
- print_('', 'fd=%s %s ' % (file.fd, file.path))
+ if pinfo['open_files']:
+ print_('open-files', 'PATH')
+ for i, file in enumerate(pinfo['open_files']):
+ if not verbose and i >= NON_VERBOSE_ITERATIONS:
+ print_("", "[...]")
+ break
+ print_('', file.path)
+ else:
+ print_('open-files', '')
- if pinfo['threads'] and len(pinfo['threads']) > 1:
- print_('running threads', '')
- for thread in pinfo['threads']:
- print_('', 'id=%s, user-time=%s, sys-time=%s' % (
- thread.id, thread.user_time, thread.system_time))
- if pinfo['connections'] not in (ACCESS_DENIED, []):
- print_('open connections', '')
+ if pinfo['connections']:
+ template = '%-5s %-25s %-25s %s'
+ print_('connections',
+ template % ('PROTO', 'LOCAL ADDR', 'REMOTE ADDR', 'STATUS'))
for conn in pinfo['connections']:
if conn.type == socket.SOCK_STREAM:
type = 'TCP'
@@ -147,19 +251,76 @@ def run(pid):
rip, rport = '*', '*'
else:
rip, rport = conn.raddr
- print_('', '%s:%s -> %s:%s type=%s status=%s' % (
- lip, lport, rip, rport, type, conn.status))
+ print_('', template % (
+ type,
+ "%s:%s" % (lip, lport),
+ "%s:%s" % (rip, rport),
+ conn.status))
+ else:
+ print_('connections', '')
+
+ if pinfo['threads'] and len(pinfo['threads']) > 1:
+ template = "%-5s %15s %15s"
+ print_('threads', template % ("TID", "USER", "SYSTEM"))
+ for i, thread in enumerate(pinfo['threads']):
+ if not verbose and i >= NON_VERBOSE_ITERATIONS:
+ print_("", "[...]")
+ break
+ print_('', template % thread)
+ print_('', "total=%s" % len(pinfo['threads']))
+ else:
+ print_('threads', '')
+
+ if hasattr(proc, "rlimit"):
+ res_names = [x for x in dir(psutil) if x.startswith("RLIMIT")]
+ resources = []
+ for res_name in res_names:
+ try:
+ soft, hard = proc.rlimit(getattr(psutil, res_name))
+ except psutil.AccessDenied:
+ pass
+ else:
+ resources.append((res_name, soft, hard))
+ if resources:
+ print_("res-limits",
+ "RLIMIT SOFT HARD")
+ for res_name, soft, hard in resources:
+ if soft == psutil.RLIM_INFINITY:
+ soft = "infinity"
+ if hard == psutil.RLIM_INFINITY:
+ hard = "infinity"
+ print_('', "%-20s %10s %10s" % (
+ RLIMITS_MAP.get(res_name, res_name), soft, hard))
+
+ if hasattr(proc, "environ") and pinfo['environ']:
+ template = "%-25s %s"
+ print_("environ", template % ("NAME", "VALUE"))
+ for i, k in enumerate(sorted(pinfo['environ'])):
+ if not verbose and i >= NON_VERBOSE_ITERATIONS:
+ print_("", "[...]")
+ break
+ print_("", template % (k, pinfo['environ'][k]))
+
+ if pinfo['memory_maps']:
+ template = "%-8s %s"
+ print_("mem-maps", template % ("RSS", "PATH"))
+ maps = sorted(pinfo['memory_maps'], key=lambda x: x.rss, reverse=True)
+ for i, region in enumerate(maps):
+ if not verbose and i >= NON_VERBOSE_ITERATIONS:
+ print_("", "[...]")
+ break
+ print_("", template % (convert_bytes(region.rss), region.path))
def main(argv=None):
- if argv is None:
- argv = sys.argv
- if len(argv) == 1:
- sys.exit(run(os.getpid()))
- elif len(argv) == 2:
- sys.exit(run(int(argv[1])))
- else:
- sys.exit('usage: %s [pid]' % __file__)
+ parser = argparse.ArgumentParser(
+ description="print information about a process")
+ parser.add_argument("pid", type=int, help="process pid")
+ parser.add_argument('--verbose', '-v', action='store_true',
+ help="print more info")
+ args = parser.parse_args()
+ run(args.pid, args.verbose)
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/scripts/procsmem.py b/scripts/procsmem.py
index 7c14dca3..9d43be70 100755
--- a/scripts/procsmem.py
+++ b/scripts/procsmem.py
@@ -98,5 +98,6 @@ def main():
print("warning: access denied for %s pids" % (len(ad_pids)),
file=sys.stderr)
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/scripts/ps.py b/scripts/ps.py
index 8aa3d3f4..b85790d6 100755
--- a/scripts/ps.py
+++ b/scripts/ps.py
@@ -17,6 +17,7 @@ import time
import psutil
+
PROC_STATUSES_RAW = {
psutil.STATUS_RUNNING: "R",
psutil.STATUS_SLEEPING: "S",
diff --git a/scripts/top.py b/scripts/top.py
index 0c99047e..70dbf6c9 100755
--- a/scripts/top.py
+++ b/scripts/top.py
@@ -14,8 +14,8 @@ $ python scripts/top.py
CPU1 [||| ] 7.8%
CPU2 [ ] 2.0%
CPU3 [||||| ] 13.9%
- Mem [||||||||||||||||||| ] 49.8% 4920M/9888M
- Swap [ ] 0.0% 0M/0M
+ Mem [||||||||||||||||||| ] 49.8% 4920M / 9888M
+ Swap [ ] 0.0% 0M / 0M
Processes: 287 (running=1, sleeping=286, zombie=1)
Load average: 0.34 0.54 0.46 Uptime: 3 days, 10:16:37
@@ -48,12 +48,14 @@ import psutil
# --- curses stuff
+
def tear_down():
win.keypad(0)
curses.nocbreak()
curses.echo()
curses.endwin()
+
win = curses.initscr()
atexit.register(tear_down)
curses.endwin()
@@ -75,6 +77,7 @@ def print_line(line, highlight=False):
raise
else:
lineno += 1
+
# --- /curses stuff
@@ -137,7 +140,7 @@ def print_header(procs_status, num_procs):
perc))
mem = psutil.virtual_memory()
dashes, empty_dashes = get_dashes(mem.percent)
- line = " Mem [%s%s] %5s%% %6s/%s" % (
+ line = " Mem [%s%s] %5s%% %6s / %s" % (
dashes, empty_dashes,
mem.percent,
str(int(mem.used / 1024 / 1024)) + "M",
@@ -148,7 +151,7 @@ def print_header(procs_status, num_procs):
# swap usage
swap = psutil.swap_memory()
dashes, empty_dashes = get_dashes(swap.percent)
- line = " Swap [%s%s] %5s%% %6s/%s" % (
+ line = " Swap [%s%s] %5s%% %6s / %s" % (
dashes, empty_dashes,
swap.percent,
str(int(swap.used / 1024 / 1024)) + "M",
@@ -229,5 +232,6 @@ def main():
except (KeyboardInterrupt, SystemExit):
pass
+
if __name__ == '__main__':
main()
diff --git a/scripts/who.py b/scripts/who.py
index f64c0093..046ec23f 100755
--- a/scripts/who.py
+++ b/scripts/who.py
@@ -29,5 +29,6 @@ def main():
datetime.fromtimestamp(user.started).strftime("%Y-%m-%d %H:%M"),
user.host))
+
if __name__ == '__main__':
main()