For a solution cross-Platform, use the package psutil.
1 - Install it from github or (easier) with Pip:
pip install psutil
2 - Run the following example 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 just the names, for example, just do:
processos = [proc.name() for proc in ps.process_iter()]
The list with the methods of accessing the process information you can use (in the variable proc, illustrated in the above code) is in the class documentation Process.
To the letter, only the first one worked, @miguel.
– Benedito
@Benedito still helped. You tried them all right? I will eliminate the others, because as I did not test I will take to have no wrong alternatives
– Miguel