Pythonで、Windowsタスクマネージャーのプロセスを表示する方法についてソースコード付きでまとめました。
Windowsタスクマネージャーのプロセス
Python標準モジュール「subprocess」でWindowsタスクマネージャーのプロセスから、メモリの使用量を取得できます。
サンプルコード(Python3)
サンプルプログラムのソースコードです。
# -*- coding:utf-8 -*-
import subprocess
# タスクマネージャーのプロセルを取得
proc = subprocess.Popen('tasklist', shell=True, stdout=subprocess.PIPE)
# 1行ずつ表示
for line in proc.stdout:
print(line.decode('shift-jis'))
"""
イメージ名 PID セッション名 セッション# メモリ使用量
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 13,104 K
Registry 96 Services 0 22,876 K
smss.exe 360 Services 0 452 K
csrss.exe 512 Services 0 1,864 K
:
"""
| – | 関連記事 |
|---|---|
| 1 | ■Python入門 基本文法 |

コメント