當前位置: 首頁>>代碼示例>>Golang>>正文


Golang syscall.Sysctl函數代碼示例

本文整理匯總了Golang中syscall.Sysctl函數的典型用法代碼示例。如果您正苦於以下問題:Golang Sysctl函數的具體用法?Golang Sysctl怎麽用?Golang Sysctl使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Sysctl函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

func init() {
	// Seems like kern.osreldate is veiled on latest OS X. We use
	// kern.osrelease instead.
	osver, err := syscall.Sysctl("kern.osrelease")
	if err != nil {
		return
	}
	var i int
	for i = range osver {
		if osver[i] != '.' {
			continue
		}
	}
	// The IPV6_RECVPATHMTU and IPV6_PATHMTU options were
	// introduced in OS X 10.7 (Darwin 11.0.0).
	// See http://support.apple.com/kb/HT1633.
	if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '1' {
		ctlOpts[ctlTrafficClass].name = sysIPV6_TCLASS
		ctlOpts[ctlTrafficClass].length = 4
		ctlOpts[ctlTrafficClass].marshal = marshalTrafficClass
		ctlOpts[ctlTrafficClass].parse = parseTrafficClass
		ctlOpts[ctlHopLimit].name = sysIPV6_HOPLIMIT
		ctlOpts[ctlHopLimit].marshal = marshalHopLimit
		ctlOpts[ctlPacketInfo].name = sysIPV6_PKTINFO
		ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
		sockOpts[ssoReceiveTrafficClass].level = ianaProtocolIPv6
		sockOpts[ssoReceiveTrafficClass].name = sysIPV6_RECVTCLASS
		sockOpts[ssoReceiveTrafficClass].typ = ssoTypeInt
		sockOpts[ssoReceiveHopLimit].name = sysIPV6_RECVHOPLIMIT
		sockOpts[ssoReceivePacketInfo].name = sysIPV6_RECVPKTINFO
		sockOpts[ssoReceivePathMTU].level = ianaProtocolIPv6
		sockOpts[ssoReceivePathMTU].name = sysIPV6_RECVPATHMTU
		sockOpts[ssoReceivePathMTU].typ = ssoTypeInt
	}
}
開發者ID:xunmengfeng,項目名稱:patchwork,代碼行數:35,代碼來源:sys_darwin.go

示例2: getInfo

func getInfo() ([]Info, error) {

	cpu, err := syscall.Sysctl("machdep.cpu.vendor")
	if err != nil {
		return nil, err
	}

	fmt.Println(cpu)
/*	
type Info struct {
	CPU        int32    `json:"cpu"`
	VendorId   string   `json:"vendorId"`
	Family     string   `json:"family"`
	Model      string   `json:"model"`
	Stepping   int32    `json:"stepping"`
	PhysicalId string   `json:"physicalId"`
	CoreId     string   `json:"coreId"`
	Cores      int32    `json:"cores"`
	ModelName  string   `json:"modelName"`
	Mhz        float64  `json:"mhz"`
	CacheSize  int32    `json:"cacheSize"`
	Flags      []string `json:"flags"`
}*/
	return nil, nil
}
開發者ID:entuerto,項目名稱:sysmon,代碼行數:25,代碼來源:cpu_darwin.go

示例3: osVersion

// osVersion returns the OS version.
func osVersion() string {
	release, err := syscall.Sysctl("kern.osrelease")
	if err != nil {
		return "0.0"
	}
	return release
}
開發者ID:Cdim,項目名稱:pholcus,代碼行數:8,代碼來源:agent_bsd.go

示例4: supportsIPv6MulticastDeliveryOnLoopback

func supportsIPv6MulticastDeliveryOnLoopback() bool {
	switch runtime.GOOS {
	case "freebsd":
		// See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
		// Even after the fix, it looks like the latest
		// kernels don't deliver link-local scoped multicast
		// packets correctly.
		return false
	case "darwin":
		// See http://support.apple.com/kb/HT1633.
		s, err := syscall.Sysctl("kern.osrelease")
		if err != nil {
			return false
		}
		ss := strings.Split(s, ".")
		if len(ss) == 0 {
			return false
		}
		// OS X 10.9 (Darwin 13) or above seems to do the
		// right thing; preserving the packet header as it's
		// needed for the checksum calcuration with pseudo
		// header on loopback multicast delivery process.
		// If not, you'll probably see what is the slow-acting
		// kernel crash caused by lazy mbuf corruption.
		// See ip6_mloopback in netinet6/ip6_output.c.
		if mjver, err := strconv.Atoi(ss[0]); err != nil || mjver < 13 {
			return false
		}
		return true
	default:
		return true
	}
}
開發者ID:ehalpern,項目名稱:go-mysql-elasticsearch,代碼行數:33,代碼來源:helper_bsd.go

示例5: LoadAvg

func LoadAvg() (s []string) {

	v, err := syscall.Sysctl(sysctl)
	t := time.Now()
	etime := strconv.FormatInt(t.Unix(), 10)

	if err != nil {
		fmt.Println(err)
	}
	b := []byte(v)
	var l loadavg = *(*loadavg)(unsafe.Pointer(&b[0]))

	scale := float64(l.scale)
	c := strconv.FormatFloat(float64(l.ldavg[0])/scale, 'f', 2, 64)
	d := strconv.FormatFloat(float64(l.ldavg[1])/scale, 'f', 2, 64)
	e := strconv.FormatFloat(float64(l.ldavg[2])/scale, 'f', 2, 64)

	// returning as load.load.metric because that's what collectd does
	f := fmt.Sprintf("load.load.shortterm %s %s", c, etime)
	s = append(s, f)
	g := fmt.Sprintf("load.load.midterm %s %s", d, etime)
	s = append(s, g)
	h := fmt.Sprintf("load.load.longterm %s %s", e, etime)
	s = append(s, h)
	return s
}
開發者ID:eholzbach,項目名稱:lespace,代碼行數:26,代碼來源:load_fbsd.go

示例6: init

func init() {
	// Seems like kern.osreldate is veiled on latest OS X. We use
	// kern.osrelease instead.
	osver, err := syscall.Sysctl("kern.osrelease")
	if err != nil {
		return
	}
	var i int
	for i = range osver {
		if osver[i] != '.' {
			continue
		}
	}
	// The IP_PKTINFO was introduced in OS X 10.7 (Darwin
	// 11.0.0). See http://support.apple.com/kb/HT1633.
	if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '1' {
		ctlOpts[ctlPacketInfo].name = sysIP_PKTINFO
		ctlOpts[ctlPacketInfo].length = sysSizeofInetPktinfo
		ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
		ctlOpts[ctlPacketInfo].parse = parsePacketInfo
		sockOpts[ssoPacketInfo].name = sysIP_RECVPKTINFO
		sockOpts[ssoPacketInfo].typ = ssoTypeInt
		sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
	}
}
開發者ID:XavierBerger,項目名稱:go.net,代碼行數:25,代碼來源:sys_darwin.go

示例7: hostname

func hostname() (name string, err error) {
	name, err = syscall.Sysctl("kern.hostname")
	if err != nil {
		return "", NewSyscallError("sysctl kern.hostname", err)
	}
	return name, nil
}
開發者ID:RajibTheKing,項目名稱:gcc,代碼行數:7,代碼來源:sys_bsd.go

示例8: osName

// osName returns the name of the OS.
func osName() string {
	name, err := syscall.Sysctl("kern.ostype")
	if err != nil {
		return runtime.GOOS
	}
	return name
}
開發者ID:Cdim,項目名稱:pholcus,代碼行數:8,代碼來源:agent_bsd.go

示例9: IsVTXDisabled

// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start.
// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started.
func (d *Driver) IsVTXDisabled() bool {
	features, err := syscall.Sysctl("machdep.cpu.features")
	if err != nil {
		log.Debugf("Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v", err)
		return false
	}
	return isVTXDisabled(features)
}
開發者ID:usmanismail,項目名稱:machine,代碼行數:10,代碼來源:virtualbox_darwin.go

示例10: Hostname

func Hostname() (name string, err Error) {
	var errno int
	name, errno = syscall.Sysctl("kern.hostname")
	if errno != 0 {
		return "", NewSyscallError("sysctl kern.hostname", errno)
	}
	return name, nil
}
開發者ID:rapgamer,項目名稱:golang-china,代碼行數:8,代碼來源:sys_bsd.go

示例11: trySysctl

func trySysctl() (string, error) {
	v, err := syscall.Sysctl("osxfuse.version.number")
	if err != nil {
		log.Debug("mount: sysctl osxfuse.version.number:", "failed")
		return "", err
	}
	log.Debug("mount: sysctl osxfuse.version.number:", v)
	return v, nil
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:9,代碼來源:mount_darwin.go

示例12: getOSInfo

func getOSInfo() (*OSInfo, error) {
	osinfo := &OSInfo{}
	var err error
	osinfo.Name, err = syscall.Sysctl("kern.ostype")
	if err != nil {
		return nil, err
	}
	osinfo.Version, err = syscall.Sysctl("kern.osrelease")
	if err != nil {
		return nil, err
	}
	osinfo.Id = osinfo.Name
	osinfo.IdLike = osinfo.Name
	osinfo.PrettyName = osinfo.Name + " Kernel Version " + osinfo.Version
	osinfo.VersionId = osinfo.Version
	osinfo.HomeURL = "www.apple.com"
	return osinfo, nil
}
開發者ID:m1911,項目名稱:hyper,代碼行數:18,代碼來源:sysinfo_darwin.go

示例13: getSystemUptime

// Returns system uptime as time.Duration.
func getSystemUptime() (uptime time.Duration, err error) {
	val, err := syscall.Sysctl("kern.boottime")
	if err != nil {
		return 0, err
	}
	buf := []byte(val)
	tv := *syscall.Timeval(unsafe.Pointer(&buf[0]))

	return time.Since(time.Unix(tv.Unix())), nil
}
開發者ID:0987363,項目名稱:zfswatcher,代碼行數:11,代碼來源:osutil_freebsd.go

示例14: GetSystemInfo

// GetSystemInfo return system info
func GetSystemInfo() (*SystemInfo, error) {
	hostname, err := syscall.Sysctl("kern.hostname")

	if err != nil || hostname == "" {
		return nil, errors.New("Can't read hostname info")
	}

	os, err := syscall.Sysctl("kern.ostype")

	if err != nil || os == "" {
		return nil, errors.New("Can't read os info")
	}

	kernel, err := syscall.Sysctl("kern.osrelease")

	if err != nil || kernel == "" {
		return nil, errors.New("Can't read kernel info")
	}

	arch, err := syscall.Sysctl("kern.version")

	if err != nil || arch == "" {
		return nil, errors.New("Can't read arch info")
	}

	archSlice := strings.Split(arch, "/")

	if len(archSlice) != 2 {
		return nil, errors.New("Can't read arch info")
	}

	cleanArch := strings.ToLower(strings.Replace(archSlice[len(archSlice)-1], "RELEASE_", "", -1))

	return &SystemInfo{
		Hostname:     hostname,
		OS:           os,
		Distribution: DARWIN_OSX,
		Version:      getOSXVersion(),
		Kernel:       kernel,
		Arch:         cleanArch,
	}, nil
}
開發者ID:essentialkaos,項目名稱:ek,代碼行數:43,代碼來源:info_darwin.go

示例15: init

func init() {
	if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
		archs, _ := syscall.Sysctl("kern.supported_archs")
		for _, s := range strings.Split(archs, " ") {
			if strings.TrimSpace(s) == "amd64" {
				freebsd32o64 = true
				break
			}
		}
	}
}
開發者ID:MauroJr,項目名稱:evergreen,代碼行數:11,代碼來源:sys_freebsd.go


注:本文中的syscall.Sysctl函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。