sysconf() Examples

sysconf() is a useful library call that gives us various limits defined on linux box. It can be used at run-time and if required, take decision based on the result. During the lifetime of the process, these limits are not changed.
From the man page
SYNOPSIS
       #include <unistd.h>

       long sysconf(int name);


Here is an example:

#include <unistd.h> 
#include <stdio.h> 

int main(int argc, char *argv[])
{
    fprintf(stdout, "Max open files per process: %ld\n", 
            sysconf(_SC_OPEN_MAX)); 
    fprintf(stdout, "Max processes  per uid    : %ld\n", 
            sysconf(_SC_CHILD_MAX));
    fprintf(stdout, "No. of clock ticks per sec: %ld\n", 
            sysconf(_SC_CLK_TCK)); 
    fprintf(stdout, "Max open streams per proc : %ld\n", 
            sysconf(_SC_STREAM_MAX)); 
    return 0; 
}


And the output on my box:

Max open files per process: 1024
Max processes  per uid    : 999
No. of clock ticks per sec: 100
Max open streams per proc : 16

Labels: , , ,