我是python编程的新手。通过在互联网上搜索 python 文档来编写此脚本。
任何人都可以帮助我仅将第二列作为“ps aux”命令的输出(即仅 PID 列)。
#script to print the processid
import os
import commands
out=commands.getoutput('ps aux') # to get the process listing in out
#print out
#print out[2] #print only second column from out
print out[:2]
output of "print out" statement
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 5728 1068 ? Ss Oct13 0:07 /sbin/init
root 2 0.0 0.0 0 0 ? S< Oct13 0:00 [kthreadd]
root 3 0.0 0.0 …Run Code Online (Sandbox Code Playgroud) python ×1