Douglas Su
Douglas Su

Reputation: 3364

How to list all types (running, zombie, etc.) of processes currently in linux with native python library

I want to list all processes' information currently exist in Linux system. I find that someone uses psutil library to accomplish this task. However, my development environment can only support native Python library. It means that I can't use any external modules.

It there exist a simple way to accomplish this mission?

Thanks.

Upvotes: 0

Views: 200

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180401

Not exactly what you are trying to accomplish but linux commands can be run using the subprocess module:

import subprocess

proc = subprocess.Popen("pstree",stdout=subprocess.PIPE)
proc.communicate()[0]

proc = subprocess.Popen(["ps" ,"aux"],stdout=subprocess.PIPE)
proc.communicate()[0]

Upvotes: 1

Related Questions