// gcc -fPIC -shared sysconf-caching.c -ldl -o sysconf-caching.so #define _GNU_SOURCE 1 #include #include #include static long int (*real_sysconf)(int name); long int sysconf(int name) { if (!real_sysconf) real_sysconf = dlsym(RTLD_NEXT, "sysconf"); if (name == _SC_NPROCESSORS_ONLN) { static int cache = -1; if (cache == -1) cache = real_sysconf( _SC_NPROCESSORS_ONLN); return cache; } return real_sysconf(name); }