停止读取Python中的进程输出而不挂起?
import osimport time process = os.popen("top").readlines()time.sleep(1)os.popen("killall top")print process
process = os.popen("top").readlines()
import osimport timeimport subprocess process = subprocess.Popen('top')time.sleep(2)os.popen("killall top")print process
<subprocess.Popen object at 0x97a50cc>
import osimport timeimport subprocess process = subprocess.Popen('top').readlines()time.sleep(2)os.popen("killall top")print process
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 31735 Barakat 20 0 246m 52m 20m S 19.4 2.7 13:54.91 totem 1907 root 20 0 91264 45m 15m S 1.9 2.3 38:54.14 Xorg 2138 Barakat 20 0 17356 5368 4284 S 1.9 0.3 3:00.15 at-spi-registry 2164 Barakat 9 -11 164m 7372 6252 S 1.9 0.4 2:54.58 pulseaudio 2394 Barakat 20 0 27212 9792 8256 S 1.9 0.5 6:01.48 multiload-apple 6498 Barakat 20 0 56364 30m 18m S 1.9 1.6 0:03.38 pyshell 1 root 20 0 2880 1416 1208 S 0.0 0.1 0:02.02 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.12 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:02.07 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
MMMHUHU
慕田峪4524236
MMTTMM
相关分类