Skip to content

Instantly share code, notes, and snippets.

@hyounggyu
Created June 12, 2017 05:42
Show Gist options
  • Save hyounggyu/6b15da78366c32cf0814e83e8275c246 to your computer and use it in GitHub Desktop.
Save hyounggyu/6b15da78366c32cf0814e83e8275c246 to your computer and use it in GitHub Desktop.
import json
import zmq
import psutil
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5556")
while True:
pinfo = []
for proc in psutil.process_iter():
try:
pinfo.append(proc.as_dict(attrs=['pid', 'name']))
except psutil.NoSuchProcess:
pass
socket.send_string(json.dumps(pinfo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment