Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the arguments to sysctl()?

Tags:

c

unix

macos

system

I checked the man pages and documentation but they only discuss the command line call. I am talking about the C function. Two questions about it:

  • What are the arguments to sysctl() in C? (I just want a general description of what each argument is and what it is used for)
  • Is the sysctl() call still valid in Mac OS X Lion?

I am on Mac OS X Snow Leopard using Xcode 3.2.6

like image 911
fdh Avatar asked Feb 05 '12 00:02

fdh


1 Answers

Well, quoting this page, assuming it has the prototype:

int sysctl (int *name,
            int nlen, 
            void *oldval,
            size_t *oldlenp,
            void *newval, 
            size_t newlen);

then it's parameters would be as follows:

  • name -> points to an array of integers: each of the integer values identifies a sysctl item, either a directory or a leaf node file. The symbolic names for such values are defined in <linux/sysctl.h>.
  • nlen -> states how many integer numbers are listed in the array name: to reach a particular entry you need to specify the path through the subdirectories, so you need to tell how long is such path.
  • oldval -> is a pointer to a data buffer where the old value of the sysctl item must be stored. If it is NULL, the system call won't return values to user space.
  • oldlenp -> points to an integer number stating the length of the oldval buffer. The system call changes the value to reflect how much data has been written, which can be less than the buffer length.
  • newval -> points to a data buffer hosting replacement data: the kernel will read this buffer to change the sysctl entry being acted upon. If it is NULL, the kernel value is not changed.
  • newlen -> is the length of newval. The kernel will read no more than newlen bytes from newval.

I'd recommend you read that entire page, since it provides more extensive details. And as for it being valid in Mac OS X Lion, I'm not sure, but I'd imagine.

Hope I helped!

like image 190
Miguel Avatar answered Oct 14 '22 07:10

Miguel