0

I'm working in a Unix-Like Kernel called Minix 3.

I am having some trouble creating a function within the kernel that will allow me to output the number of processes being run. This is my code I have so far:

PUBLIC void numproc_dmp()
{

   printf("Number of Processes Running");
   echo ps -ax | wc -l     
}

What this function is supposed to do is when F8 is pressed it will show the amount of processes running.

The command ps -ax | wc -l works fine when entered into the CLI interface and shows the number of processes but I have no idea how to implement it into the function as it won't execute.

The error I receive is that "the identifier is not expected".

EDIT:

I am still struggling... After trying a new method i got rid of the errors but no output...

PUBLIC void numproc_dmp()
{
  printf("Number of Processes Running");
  popen("ps -ax | wc -l", "r");
  printf("%s", popen("ps -ax | wc -l", "r"));
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Gamme40
  • 33
  • 6
  • 1
    Do you understand what you're proposing? The kernel is the authoritative source of the number of running processes. You can't implement the process count in the kernel by asking a user-space process: it's going to have to ask the kernel, and that's a circular definition. – nobody Aug 24 '14 at 15:32
  • i assumed if i could redirect the output of the user-space command to a variable i would be able to output the number of currently running processes. I don't know how to do that though... i Am quite a beginner when it comes to this. im not editing the kernel itself but rather just 3 files: dmp_pm.c, dmp.c and proto.h contained in the /usr/src/servers/is/ folder – Gamme40 Aug 24 '14 at 16:29
  • I have posted the answer here: https://stackoverflow.com/questions/7234369/number-of-running-processes-on-a-system-c-question/25482662#25482662 – Bennie Sep 05 '14 at 11:41

0 Answers0