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
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.