Last active
July 5, 2017 07:37
-
-
Save isaaguilar/401589929d5704b087b29cd46605fd42 to your computer and use it in GitHub Desktop.
a version of `ps ax` for python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from subprocess import Popen, PIPE | |
# Equivilent to `ps ax|grep search_string` | |
p2 = Popen(["grep", search_string], stdin=PIPE, stdout=PIPE) # search_string | |
p1 = Popen(["ps", "ax"], stdout=p2.stdin) | |
# Break up results into invidual lines | |
results = p2.communicate()[0].split("\n") | |
# Now iterate thru the list, filter out grep, and print pids | |
pids = [] | |
for line in results: | |
if "grep" in line: | |
continue | |
pids.append(re.sub("\ .*$", "", line.lstrip(" "))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment