Checking for NPTL

The following snippet checks a running system for NPTL.

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

int isnptl (void)
        size_t n = confstr (_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
        if (n > 0)
                char *buf = alloca (n);
                confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
                if (strstr (buf, "NPTL"))
                        return 1;
        return 0;

int main(void)
        printf("NPTL: %s\n", isnptl() ? "yes" : "no");
        return 0;

You probably do not want to check what is running at compile time, as the libraries can be easily switched around on you. It's more important to ask why you even need to check -- of course the best way is just to make your code work with all versions of the threading libraries.

IA64wiki: CheckingForNPTL (last edited 2009-12-10 03:13:51 by localhost)

Gelato@UNSW is sponsored by
the University of New South Wales National ICT Australia The Gelato Federation Hewlett-Packard Company Australian Research Council
Please contact us with any questions or comments.