Finding the command for a specific PID in Linux from Python

后端 未结 7 902
半阙折子戏
半阙折子戏 2020-12-19 05:33

I\'d like to know if it\'s possible to find out the \"command\" that a PID is set to. When I say command, I mean what you see in the last column when you run the command \"t

7条回答
  •  盖世英雄少女心
    2020-12-19 06:15

    PLEASE, do not use /proc filesystem in production code. Instead, use well-defined POSIX interfaces, such as glibc calls and standard shell commands! Make the Linux world more standardized, it really needs to!

    What you need is well achieved by invoking a shell command

    ps -p  -o cmd h
    

    No parsing is needed!

    Let alone that reading shell command output from python takes no more effort than reading from a file in /proc. And this makes your program more portable, either!

提交回复
热议问题