Bozic
Bozic

Reputation: 157

Counting number of processes in Minix

I need to create a user program that will be able to see how many processes are running with help of system calls. I found out that getsysinfo() function can give me the result but I get errors when I try to compile my code.
I used the following code:

struct kinfo kinfo;
int nr_tasks, nr_procs;
getsysinfo(PM_PROC_NR, SI_KINFO, &kinfo);
nr_procs = kinfo.nr_pro;

The problem is, I get many errors when compiling. I see that there are many undefined variables and I don't know what libraries I should include. The code just seems too shallow to understand.

Upvotes: 0

Views: 1105

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754080

A Google search for 'minix getsysinfo' reveals various sources, including:

  • How does function getsysinfo work in Minix

    This says, amongst other things, that the function is only accessible inside the kernel, not in user code. It also contains a code fragment very similar to what you show, along with the commentary:

    endpoint_t who // from whom to request info
    int what // what information is requested
    void *where // where to put it
    size_t size // how big it should be
    

    Example:

    struct kinfo pinf;
    int num_procs;
    getsysinfo(PM_PROC_NR, SI_KINFO, &pinf);
    num_procs = pinf.nr_pro;
    

    It's at least somewhat curious that the description says '4 arguments' and the example uses just '3 arguments' (and your code does too).

  • Minix identifier search: getsysinfo()

    Defined as a function in:

       minix/lib/libsys/getsysinfo.c, line 8 
    

    Defined as a function prototype in:

       minix/include/minix/sysinfo.h, line 8 
    

    One of the fragments of code also referenced shows a call:

      if (getsysinfo(RS_PROC_NR, SI_PROCPUB_TAB, rprocpub, sizeof(rprocpub)) != OK …
    

    This shows the fourth argument described but omitted from the example quoted in the question and the first link.

Both those and the other references look like kernel code rather than user code. So, superficially, if you're writing a user-side program for Minix, you can't access this function because it is in the kernel, not in the user-callable C libraries.

Upvotes: 1

Related Questions