For a cross-platform solution, use the psutil package.
1 - Install it from github or (easier) with pip:
pip install psutil
2 - Run the following sample program:
import psutil as ps
print('Lista de processos em execução:')
for proc in ps.process_iter():
info = proc.as_dict(attrs=['pid', 'name'])
print('Processo: {} (PID: {})'.format(info['pid'], info['name']))
It lists the data (name and pid) of the processes one by one, obtained through a dictionary. But if you want to build a list with only the names, for example, just do:
processos = [proc.name() for proc in ps.process_iter()]
The list with the process information access methods you can use (in the proc
variable, shown in the code above) is in the documentation of class Process
.