15 lines
411 B
Python
15 lines
411 B
Python
import subprocess
|
|
|
|
|
|
def get_services_list():
|
|
data = subprocess.check_output(['ps', '-Ao', 'user,comm,%cpu', '--sort=-pcpu'])
|
|
data = data.decode('utf-8')
|
|
|
|
result = []
|
|
for line in data.split('\n')[1:6]:
|
|
cur = line.split(" ")
|
|
cur = [x for x in cur if len(x)]
|
|
if len(cur) == 3:
|
|
result.append({"user": cur[0], "command": cur[1], 'cpu': cur[2]})
|
|
|
|
return result
|