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:
system("ps -A");
This function displays all running process in the terminal.
But I want to this functionality using a POSIX function. I am not looking for a ready made code.
Can some one point me to the function name or any manual ?
No POSIX function exists to list running processes. That is OS specific, not portable, rarely needed by applications and thus not part of POSIX.
But since you need this on Linux, the most POSIXy solution would be to use functions
opendir()/readdir()/closedir()to iterate over the content of/procspecial file system.All numeric entries in the directory are PIDs of running processes. Check the content the
man 5 procfor details what information about the running processes can be obtained from there. Then you can use theopen()/read()/close()orreadlink()calls to retrieve the information about a particular process from the/proc/NNN/*files.On Linux, the standard tools like
psandtopuse the/procto gather the information about processes. It is official Linux’ interface to the information about running processes.