mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-04-16 16:00:13 +02:00

> Alpine Linux ASCII logo has been borrowed from Neofetch (see <404c955e8f
>).
- Known bug :
- The `Disk` entry is not compatible against the BusyBox `df` implementation.
- Alpine users are advised to **disable** it from configuration.
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""Simple class (acting as a singleton) to handle processes listing"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
from subprocess import CalledProcessError, DEVNULL, check_output
|
|
|
|
from archey.singleton import Singleton
|
|
|
|
|
|
class Processes(metaclass=Singleton):
|
|
"""At startup, instantiate this class to populate a list of running processes"""
|
|
def __init__(self):
|
|
try:
|
|
self._processes = check_output(
|
|
[
|
|
'ps',
|
|
(('-u' + str(os.getuid())) if os.getuid() != 0 else '-ax'),
|
|
'-o', 'comm',
|
|
'--no-headers'
|
|
],
|
|
universal_newlines=True, stderr=DEVNULL
|
|
).splitlines()
|
|
except CalledProcessError:
|
|
# The available `ps` implementation may not support passed parameters (hello BusyBox).
|
|
# Let's fall-back on a much simpler approach.
|
|
self._processes = check_output(
|
|
['ps', '-o', 'comm'],
|
|
universal_newlines=True
|
|
).splitlines()[1:]
|
|
except FileNotFoundError:
|
|
print(
|
|
"Please, install first `procps` on your distribution.",
|
|
file=sys.stderr
|
|
)
|
|
sys.exit(1)
|
|
|
|
def get(self):
|
|
"""Simple getter to retrieve the processes list"""
|
|
return self._processes
|