Giter Club home page Giter Club logo

numcpus's Introduction

numcpus

Go Reference GitHub Action Status

Package numcpus provides information about the number of CPUs in the system.

It gets the number of CPUs (online, offline, present, possible, configured or kernel maximum) on Linux, Darwin, FreeBSD, NetBSD, OpenBSD, DragonflyBSD or Solaris/Illumos systems.

On Linux, the information is retrieved by reading the corresponding CPU topology files in /sys/devices/system/cpu.

On BSD systems, the information is retrieved using the hw.ncpu and hw.ncpuonline sysctls, if supported.

Not all functions are supported on Darwin, FreeBSD, NetBSD, OpenBSD, DragonflyBSD and Solaris/Illumos. ErrNotSupported is returned in case a function is not supported on a particular platform.

Usage

package main

import (
	"fmt"
	"os"

	"github.com/tklauser/numcpus"
)

func main() {
	online, err := numcpus.GetOnline()
	if err != nil {
		fmt.Fprintf(os.Stderr, "GetOnline: %v\n", err)
	}
	fmt.Printf("online CPUs: %v\n", online)

	possible, err := numcpus.GetPossible()
	if err != nil {
		fmt.Fprintf(os.Stderr, "GetPossible: %v\n", err)
	}
	fmt.Printf("possible CPUs: %v\n", possible)
}

References

numcpus's People

Contributors

dependabot[bot] avatar tklauser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

numcpus's Issues

Tests fail on ppc64

While building on Fedora Rawhide on ppc64le, numcpus doesn't seem to work properly:

Testing    in: /builddir/build/BUILD/numcpus-0.2.3/_build/src
         PATH: /builddir/build/BUILD/numcpus-0.2.3/_build/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
       GOPATH: /builddir/build/BUILD/numcpus-0.2.3/_build:/usr/share/gocode
  GO111MODULE: off
      command: go test -buildmode pie -compiler gc -ldflags " -X github.com/tklauser/numcpus/version=0.2.3 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  '"
      testing: github.com/tklauser/numcpus
github.com/tklauser/numcpus
--- FAIL: TestGetPresent (0.00s)
    numcpus_test.go:103: Present = 8
    numcpus_test.go:105: GetPresent returned 8, want 40 (getconf _NPROCESSORS_CONF)
FAIL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.