Posted By

hrbrmstr on 12/13/09


Tagged

python ps os x 64-bit 32-bit


Versions (?)

psbit.py - display apps that are either 32-bit or 64-bit


 / Published in: Python
 

  1. #!/usr/bin/python
  2.  
  3. import subprocess
  4. import sys
  5.  
  6. bitness = 64 # default to finding 64-bit processes
  7. bitflag = "4"
  8.  
  9. if (len(sys.argv) > 1):
  10. if (sys.argv[1] == "32"):
  11. bitness = 32
  12. bitflag = "0"
  13.  
  14.  
  15. ps = subprocess.Popen(['ps', '-Al'], stdout=subprocess.PIPE).communicate()[0]
  16.  
  17. processes = ps.split('\n')
  18.  
  19. nfields = len(processes[0].split()) - 1
  20.  
  21. for row in processes[1:]:
  22.  
  23. psout = row.split(None, nfields)
  24.  
  25. if (len(psout) > 4) and (psout[3].endswith(bitflag)) :
  26. print psout[nfields]

Report this snippet  

You need to login to post a comment.