diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-05 19:34:21 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-05 19:34:21 +0200 |
commit | 3204eaf4d244f1a76d1c20b2fb9773ad36db4e22 (patch) | |
tree | 2f6926d3ee71488c7dec01f0fc49d4c66d20160e | |
parent | 279f6e4219eda6af2e1d05c762b022c5d7e10456 (diff) | |
download | psutil-3204eaf4d244f1a76d1c20b2fb9773ad36db4e22.tar.gz |
improve ps.py script
-rwxr-xr-x | scripts/ps.py | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/scripts/ps.py b/scripts/ps.py index 72c315a8..f7857f21 100755 --- a/scripts/ps.py +++ b/scripts/ps.py @@ -18,32 +18,13 @@ import psutil from psutil._common import bytes2human -PROC_STATUSES_RAW = { - psutil.STATUS_RUNNING: "R", - psutil.STATUS_SLEEPING: "S", - psutil.STATUS_DISK_SLEEP: "D", - psutil.STATUS_STOPPED: "T", - psutil.STATUS_TRACING_STOP: "t", - psutil.STATUS_ZOMBIE: "Z", - psutil.STATUS_DEAD: "X", - psutil.STATUS_WAKING: "WA", - psutil.STATUS_IDLE: "I", - psutil.STATUS_LOCKED: "L", - psutil.STATUS_WAITING: "W", -} -if hasattr(psutil, 'STATUS_WAKE_KILL'): - PROC_STATUSES_RAW[psutil.STATUS_WAKE_KILL] = "WK" -if hasattr(psutil, 'STATUS_SUSPENDED'): - PROC_STATUSES_RAW[psutil.STATUS_SUSPENDED] = "V" - - def main(): today_day = datetime.date.today() - templ = "%-10s %5s %5s %5s %7s %7s %5s %-5s %5s %7s %s" - attrs = ['pid', 'cpu_percent', 'memory_percent', 'name', 'cpu_times', + templ = "%-10s %5s %5s %7s %7s %5s %6s %6s %6s %s" + attrs = ['pid', 'memory_percent', 'name', 'cpu_times', 'create_time', 'memory_info', 'status', 'nice', 'username'] - print(templ % ("USER", "PID", "%CPU", "%MEM", "VSZ", "RSS", "NICE", - "STAT", "START", "TIME", "COMMAND")) + print(templ % ("USER", "PID", "%MEM", "VSZ", "RSS", "NICE", + "STAT", "START", "TIME", "NAME")) for p in psutil.process_iter(attrs, ad_value=None): pinfo = p.info if pinfo['create_time']: @@ -79,11 +60,11 @@ def main(): nice = int(pinfo['nice']) if pinfo['nice'] else '' name = pinfo['name'] if pinfo['name'] else '' - status = PROC_STATUSES_RAW.get(pinfo['status'], pinfo['status']) +# status = PROC_STATUSES_RAW.get(pinfo['status'], pinfo['status']) + status = pinfo['status'][:5] if pinfo['status'] else '' print(templ % ( user[:10], pinfo['pid'], - pinfo['cpu_percent'], memp, vms, rss, |