Linux Confstr and uname function _ get C library and kernel information

Source: Internet
Author: User

#include <stdio.h> #include <sys/utsname.h>//unameint main (int argc, char **argv[]) {struct utsname  u; if (uname (&u)! =-1) {printf ("Get the name and information of the current kernel such as the following \ n" "   " sysname:%s\n ""   nodename:%s\n ""   release:%s\n "   "version:%s\n" "   machine:%s\n"   , U.sysname, U.nodename, U.release, U.version, u.machine);} return 0;}

The output is as follows:

Gets the name and information for the current kernel, such as the following sysname:linuxnodename:fesrelease:2.6.32-220.el6.x86_64version: #1 SMP Wed 9 08:03:13 EST 2011machine:x86_64
size_t confstr (int name, char *buf, size_t len);
The CONFSTR function gets the value of a dependent configuration string variable
1. _cs_gnu_libc_version,the GNU C Library VERSION on the This system
2. _cs_gnu_libpthread_version,the POSIX implementation supplied by this C library
3, _cs_path,a value for the PATH variable which indicates where all the POSIX.2 standard utilities can be found.
#include <stdio.h> #include <stdlib.h> #include <unistd.h>//confstrint main (int argc, char **argv[]) { Char *pathbuf, *gun_libpthread_version_buf, *gun_libc_version_buf;size_t n;n = Confstr (_cs_path,null, (size_t) 0); Pathbuf = malloc (n), if (pathbuf = = NULL) abort (), Confstr (_cs_path, Pathbuf, N);p rintf ("_cs_path, A value for the PATH varia Ble:%s\n ", pathbuf); free (pathbuf);p athbuf = Null;n = Confstr (_cs_gnu_libpthread_version,null, (size_t) 0); if (n > 0) { Gun_libpthread_version_buf = malloc (n);} if (gun_libpthread_version_buf = = NULL) abort (); Confstr (_cs_gnu_libpthread_version, GUN_LIBPTHREAD_VERSION_BUF, N); printf ("_cs_gnu_libpthread_version, the POSIX implementation supplied by this C library:%s\n", Gun_libpthread_version_ BUF); free (gun_libpthread_version_buf); gun_libpthread_version_buf = Null;n = Confstr (_cs_gnu_libc_version,null, ( size_t) 0); if (n > 0) {gun_libc_version_buf = malloc (n);} if (gun_libc_version_buf = = NULL) abort (); Confstr (_cs_gnu_libc_version, Gun_libc_versiON_BUF, N);p rintf ("_cs_gnu_libc_version, the GNU C library VERSION on this system:%s\n", gun_libc_version_buf); Free (gun_ LIBC_VERSION_BUF); gun_libc_version_buf = Null;return 0;}
the output results are as follows:

_cs_path, A value for the PATH variable:/bin:/usr/bin_cs_gnu_libpthread_version, the POSIX implementation supplied by this C LIBRARY:NPTL 2.12_cs_gnu_libc_version, the GNU C library VERSION on this system:glibc 2.12


Linux Confstr and uname function _ get C library and kernel information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.