Display all process using a posix function

前端 未结 4 952
一生所求
一生所求 2020-12-06 21:38

I am trying to display currently running process in Ubuntu.

Right now I am using system() function to print running process in the terminal. Code:

sy         


        
4条回答
  •  时光取名叫无心
    2020-12-06 21:39

    ps is a POSIX command.

    popen is a POSIX API for reading output from a command.

    If you want a pure POSIX approach (maybe you want it portable to some OS that does not provide /proc), you should run ps with POSIX-only options and fetch the output from popen.

    So, for example, maybe you want to call popen("ps -A -o pid=", "r"); and then read through the list of PIDs.

提交回复
热议问题