Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

!pip3 install psutil
Collecting psutil
  Downloading psutil-5.7.3.tar.gz (465 kB)
     |████████████████████████████████| 465 kB 2.0 MB/s 
Building wheels for collected packages: psutil
  Building wheel for psutil (setup.py) ... done
  Created wheel for psutil: filename=psutil-5.7.3-cp38-cp38-macosx_10_15_x86_64.whl size=234560 sha256=03c5b38dcb3243006fd488e10e8ff17adf038b8755afdd316ed367976181ce45
  Stored in directory: /Users/dclong/Library/Caches/pip/wheels/f6/59/c2/38111ef4c354088a156bc95fbeb5396c0cac91a0f62f7158b9
Successfully built psutil
Installing collected packages: psutil
Successfully installed psutil-5.7.3
import psutil
psutil.virtual_memory()
svmem(total=34359738368, available=16077950976, percent=53.2, used=12415860736, free=7193649152, active=8815947776, inactive=8731512832, wired=3599912960)
psutil.cpu_percent()
4.8
psutil.virtual_memory()
svmem(total=34359738368, available=16035885056, percent=53.3, used=12460191744, free=7184756736, active=8855121920, inactive=8669417472, wired=3605069824)
pids = psutil.pids()
p = psutil.Process(1)
p
psutil.Process(pid=1, name='launchd', status='running', started='2020-10-19 22:13:12')
p.username()
'root'
for p in psutil.process_iter():
    if p.username() == "dclong":
        print(p.memory_info())
        break
pmem(rss=4644864, vms=4798234624, pfaults=3825, pageins=91)
for p in psutil.process_iter():
    if p.username() == "dclong":
        print(f"Memory info: {p.memory_info()}")
        print(f"Memory pct: {p.memory_percent()}")
        print(f"CPU pct: {p.cpu_percent()}")
        break
Memory info: pmem(rss=4644864, vms=4798234624, pfaults=3825, pageins=91)
Memory pct: 0.013518333435058594
CPU pct: 0.0
p.status()
'running'
sum(
    p.memory_percent()
    for p in psutil.process_iter()
    if p.username() == "dclong" and p.status() == "running"
)
54.66163158416748
sum(
    p.cpu_percent()
    for p in psutil.process_iter()
    if p.username() == "dclong" and p.status() == "running"
)
65.39999999999999
for proc in psutil.process_iter():
    print(proc)
psutil.Process(pid=1, name='bash', started='09:39:49')
psutil.Process(pid=38, name='jupyterhub', started='09:39:49')
psutil.Process(pid=43, name='node', started='09:39:50')
psutil.Process(pid=63, name='jupyterhub-sing', started='09:39:59')
psutil.Process(pid=125, name='bash', started='09:44:41')
psutil.Process(pid=147, name='python3', started='10:01:47')
psutil.Process(pid=184, name='pyls', started='10:01:59')
psutil.Process(pid=203, name='python3', started='10:02:20')
#!/usr/bin/env python3
import psutil

for proc in psutil.process_iter():
    if proc.username() == "bendu":
        try:
            cmd = proc.cmdline()
        except:
            continue
        if "chrome" in cmd[0].lower():
            print(proc.pid)