Heather Huynh

about blog projects press
Using the getsysinfo call in MINIX
November 29, 2016

While there are a few StackOverflow questions about this, none of them really give a great tutorial for using the getsysinfo call in MINIX programs.

The first thing to understand is the structure of the getsysinfo call. The getsysinfo call takes in three arguments. These are:

endpoint_t who //from whom to request info
int what //what info is requested
void * where //where to put it

Most places include an additional size_t size, but it is not required in the call.

For “who”, it’s pretty easy enough. In most MINIX programss, you will probably want PM to handle this so you would use PM_PROC_NR. I think the other one you can use besides PM is DS (you can find this by looking through the source code and seeing who actually implements getsysinfo).

The “what” is slightly more complex. If we take a look in /usr/src/servers/pm/misc.c, we can see what exactly getsysinfo will support. Your choices for “what” you want are:

The “what” you pick is important because depending on what you pick, the type of your storage variable will change. For example, using SI_KINFO means you will have a struct kinfo. The associations are below:

The final piece is knowing what file imports the getsysinfo function. A search through the MINIX source code shows the prototype for the getsysinfo function in unistd.h on line 166. Thus, we need to include unistd.h in our program for this to run successfully. In the past, I’ve also had to include “/usr/src/servers/is/inc.h” and “/usr/src/servers/pm/mproc.h”.

As an example, say I wanted to get information about holes for memory allocation in my program.

#include <unistd.h>
#include "/usr/src/servers/is/inc.h"
#include "/usr/src/servers/pm/mproc.h"

int main(int argc, char * argv[]) {
  struct pm_mem_info pmi;
  int i;

  getsysinfo(PM_PROC_NNR, SI_MEM_ALLOC, &pmi);
  
  for(i = 0; i < _NR_HOLES; i++) {
    printf("Hole size: %d", pmi.pmi_holes[i].h_len);
  }
  return 0;
}

The above code hasn’t been tested, but it follows a program that I wrote that did successfully compile. If you still have trouble compiling because it can’t find getsysinfo, you could also try importing <sys/types.h>.

This post was created with help from the following resources: