/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/python import subprocess import sys bitness = 64 # default to finding 64-bit processes bitflag = "4" if (len(sys.argv) > 1): if (sys.argv[1] == "32"): bitness = 32 bitflag = "0" ps = subprocess.Popen(['ps', '-Al'], stdout=subprocess.PIPE).communicate()[0] processes = ps.split('\n') nfields = len(processes[0].split()) - 1 for row in processes[1:]: psout = row.split(None, nfields) if (len(psout) > 4) and (psout[3].endswith(bitflag)) : print psout[nfields]