So, this seemed simple at first, but after crawling Google and here, the answer doesn\'t seem as simple as I first thought.
Basically, I\'m editing a MINIX kernel as
Perhaps you could show us the code your wrote for capturing the result of system("ps -ax | wc -l")
, or the code you wrote to use popen
and we could help you diagnose the problem with it.
Regardless, the most efficient way I can think of to count the number of existing (not the same as running) processes on the system is to opendir("/proc") and count the number of entries that are strings of decimal digits. Each process in the system will be represented by a subdirectory of /proc, named after the decimal process id number of that process.
So, if you find "/proc/3432", for example, then you know that there exists a process with a pid of "3432". Simply count the number of subdirectories you find whose names are decimal numbers.