commit: ca0f06d0032427d52f90e89ed678050608304ebc
parent 8ae41b9a6b12c4673cfafabecd0173f649747634
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 2 Oct 2023 07:00:14 +0200
cmd/nproc.1: New
Diffstat:
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/cmd/nproc.1 b/cmd/nproc.1
@@ -0,0 +1,27 @@
+.\" utils-std: Collection of commonly available Unix tools
+.\" Copyright 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+.\" SPDX-License-Identifier: MPL-2.0
+.Dd 2023-10-02
+.Dt NPROC 1
+.Os
+.Sh NAME
+.Nm nproc
+.Nd print the number of processors
+.Sh SYNOPSIS
+.Nm
+.Op Fl a
+.Sh DESCRIPTION
+By default
+.Nm
+prints the number of currently available processors to run processes.
+This may be lower than the number of processors which can be made available, which you can see via the
+.Fl a
+option.
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr sysconf 3
+.Sh STANDARDS
+None known.
+.Sh AUTHORS
+.An Haelwenn (lanodan) Monnier Aq Mt contact@hacktivis.me
diff --git a/cmd/nproc.c b/cmd/nproc.c
@@ -2,7 +2,9 @@
// SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
// SPDX-License-Identifier: MPL-2.0
-#define _DEFAULT_SOURCE // _SC_NPROCESSORS_CONF
+// _SC_NPROCESSORS_CONF &_SC_NPROCESSORS_ONLN aren't in POSIX yet but have been accepted
+// https://www.austingroupbugs.net/view.php?id=339
+#define _DEFAULT_SOURCE
#include <stdio.h> // printf
#include <unistd.h> // sysconf, getopt, opt*
@@ -15,8 +17,7 @@ usage()
int
main(int argc, char *argv[])
{
- // _SC_NPROCESSORS_CONF &_SC_NPROCESSORS_ONLN aren't in POSIX yet but have been accepted
- // https://www.austingroupbugs.net/view.php?id=339
+ // currently available
int target = _SC_NPROCESSORS_ONLN;
int c;
@@ -24,7 +25,7 @@ main(int argc, char *argv[])
{
switch(c)
{
- case 'a': // all processors
+ case 'a': // can be made available
target = _SC_NPROCESSORS_CONF;
break;
case ':':