get_nprocs(3)

πŸ’– get_nprocs(3) β€” get number of processors πŸ’–

okay bestie, listen. this is a page from the Library Functions Manual for get_nprocs, get_nprocs_conf, and it's genuinely so useful it's giving main character energy. sit down, grab a strawberry, we're counting CPUs. πŸ“βœ¨


🌸 NAME 🌸

get_nprocs, get_nprocs_conf β€” get number of processors


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)

like, the standard one. the icon. πŸ‘‘


✨ SYNOPSIS ✨

#include <sys/sysinfo.h>

int get_nprocs(void);
int get_nprocs_conf(void);

two little functions, zero arguments, no cap. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so get_nprocs_conf() returns the number of processors configured by the operating system. that's the how many exist in theory number.

and get_nprocs() returns the number of processors currently available in the system. that's the how many are actually showing up to the group chat right now number.

and here's the tea: this may be less than the number returned by get_nprocs_conf() because processors may be offline (e.g., on hotpluggable systems). so like, configured β‰  currently awake. one of them is napping. 😴


πŸ”₯ RETURN VALUE πŸ”₯

As given in DESCRIPTION. literally just read the section above, bestie, it's right there.


πŸ’… ATTRIBUTES πŸ’…

for an explanation of the terms used in this section, see attributes(7).

  • Interface: get_nprocs(), get_nprocs_conf()
  • Attribute: Thread safety
  • Value: MT-Safe

MT-Safe!! she's safe in threads, she can be called from anywhere, she's booked and busy and unbothered. πŸ’…


🌈 STANDARDS 🌈

GNU.

that's it. that's the whole section. GNU only, deal with it. πŸƒ


πŸŽ€ NOTES πŸŽ€

the current implementation of these functions is rather expensive, since they open and parse files in the /sys filesystem each time they are called. like bestie... every single call?? every call. she's re-reading the same files over and over. obsessed with the drama of it but also, lowkey expensive. πŸ’€

fr fr if you're calling this in a hot loop, maybe don't. the manpage is literally telling you it's costly. iykyk.

also!! the following sysconf(3) calls make use of the functions documented on this page to return the same information:

np = sysconf(_SC_NPROCESSORS_CONF);     /* processors configured */
np = sysconf(_SC_NPROCESSORS_ONLN);     /* processors available */

same info, different doorway. pick your fave. πŸšͺ✨


🧚 EXAMPLES 🧚

the following example shows how get_nprocs() and get_nprocs_conf() can be used.

#include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>

int
main(void)
{
    printf("This system has %d processors configured and "
            "%d processors available.\n",
            get_nprocs_conf(), get_nprocs());
    exit(EXIT_SUCCESS);
}

not me writing a whole C program just to flex how many cores my laptop has 😭 iconic behaviour honestly. it prints both numbers and exits clean with EXIT_SUCCESS. periodt.


πŸ’œ SEE ALSO πŸ’œ


and that's the tea bestie 🫢 slay, go count some processors, and remember: configured β‰  available. 🌟

this was brought to you by Linux man-pages 6.20, dated 2026-02-08 β€” get_nprocs(3), out. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms