Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ async def get_processes(self):

process_list = []

# Get a list of processes using ps for the current user, we need the PID and the untruncated process name.
# Get a list of processes using ps for the current user, we need the PID, executable name, and the untruncated process name.
# Processes are sorted by memory usage in descending order.
ps = subprocess.Popen(
["ps", "-u", "1000", "-o", "pid,command"], stdout=subprocess.PIPE)
["ps", "-u", "1000", "-o", "pid=,comm=,command=", "--sort=-rss"], stdout=subprocess.PIPE)

output = subprocess.check_output(
('grep', '-v', 'grep'), stdin=ps.stdout)
Expand All @@ -36,18 +37,13 @@ async def get_processes(self):

# Parse output
for line in output.splitlines():
pid, name = line.decode().split(None, 1)

# If the name doesn't contain any string from the blacklist, append it
if not any(x in name for x in blacklist):
process_list.append({"pid": pid, "name": name})

# Remove blacklisted processes#
for process in process_list:
for blacklist_item in blacklist:
# Check if blacklist item is contained in the process name
if blacklist_item in process["name"]:
process_list.remove(process)
pid, name, full_name = line.decode().split(None, 2)

# If the name contains any string from the blacklist, skip it
if any(x in full_name for x in blacklist):
continue

process_list.append({"pid": pid, "name": name})

return process_list

Expand Down