当前位置: 首页>>代码示例>>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;未经允许,请勿转载。