• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang process.Process类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/shirou/gopsutil/process.Process的典型用法代码示例。如果您正苦于以下问题:Golang Process类的具体用法?Golang Process怎么用?Golang Process使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Process类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: getProcCmdline

//Returns the command line slice for a given process name
func getProcCmdline(procname string) (cmd []string, err error) {
	var proc *process.Process
	pid := getProcPID(procname)
	proc, err = process.NewProcess(int32(pid))
	cmd, err = proc.CmdlineSlice()
	return cmd, err
}
开发者ID:diogomonica,项目名称:actuary,代码行数:8,代码来源:checks.go


示例2: NewSpecProcessor

func NewSpecProcessor(
	processName string,
	prefix string,
	pid int32,
	acc telegraf.Accumulator,
	p *process.Process,
	tags map[string]string,
) *SpecProcessor {
	if processName != "" {
		tags["process_name"] = processName
	} else {
		name, err := p.Name()
		if err == nil {
			tags["process_name"] = name
		}
	}
	return &SpecProcessor{
		Prefix: prefix,
		pid:    pid,
		tags:   tags,
		fields: make(map[string]interface{}),
		acc:    acc,
		proc:   p,
	}
}
开发者ID:li-ang,项目名称:telegraf,代码行数:25,代码来源:spec_processor.go


示例3: NewSpecProcessor

func NewSpecProcessor(
	prefix string,
	acc plugins.Accumulator,
	p *process.Process,
) *SpecProcessor {
	tags := make(map[string]string)
	tags["pid"] = fmt.Sprintf("%v", p.Pid)
	if name, err := p.Name(); err == nil {
		tags["name"] = name
	}
	return &SpecProcessor{
		Prefix: prefix,
		tags:   tags,
		acc:    acc,
		proc:   p,
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:17,代码来源:spec_processor.go


示例4: NewSpecProcessor

func NewSpecProcessor(
	prefix string,
	acc telegraf.Accumulator,
	p *process.Process,
	tags map[string]string,
) *SpecProcessor {
	if name, err := p.Name(); err == nil {
		tags["process_name"] = name
	}
	return &SpecProcessor{
		Prefix: prefix,
		tags:   tags,
		fields: make(map[string]interface{}),
		acc:    acc,
		proc:   p,
	}
}
开发者ID:adithyabenny,项目名称:telegraf,代码行数:17,代码来源:spec_processor.go


示例5: hasPort

func hasPort(proc *process.Process, connections []net.ConnectionStat) bool {
	for _, connection := range connections {
		if connection.Status == "LISTEN" && connection.Pid == int32(proc.Pid) {
			return true
		}
	}

	children, err := proc.Children()
	if err == nil {
		for _, child := range children {
			if hasPort(child, connections) {
				return true
			}
		}
	}
	return false
}
开发者ID:yext,项目名称:edward,代码行数:17,代码来源:command.go


示例6: doGetPorts

func (sc *ServiceConfig) doGetPorts(proc *process.Process) ([]string, error) {
	var err error
	if len(connectionsCache) == 0 {
		connectionsCache, err = net.Connections("all")
		if err != nil {
			return nil, errors.WithStack(err)
		}
	}

	var ports []string
	var knownPorts = make(map[int]struct{})
	if sc.LaunchChecks != nil {
		for _, port := range sc.LaunchChecks.Ports {
			knownPorts[port] = struct{}{}
		}
	}
	for _, connection := range connectionsCache {
		if connection.Status == "LISTEN" {
			if _, ok := knownPorts[int(connection.Laddr.Port)]; connection.Pid == proc.Pid && !ok {
				ports = append(ports, strconv.Itoa(int(connection.Laddr.Port)))
			}
		}
	}

	children, err := proc.Children()
	// This will error out if the process has finished or has no children
	if err != nil {
		return ports, nil
	}
	for _, child := range children {
		childPorts, err := sc.doGetPorts(child)
		if err == nil {
			ports = append(ports, childPorts...)
		}
	}
	return ports, nil
}
开发者ID:yext,项目名称:edward,代码行数:37,代码来源:serviceconfig.go


示例7: getProcStatus

func getProcStatus(p *process.Process) (*ProcessStatus, error) {
	n, err := p.Name()
	if err != nil {
		return nil, err
	}
	c, err := p.Percent(0)
	if err != nil {
		return nil, err
	}
	m, err := p.MemoryInfo()
	if err != nil {
		return nil, err
	}
	return &ProcessStatus{
		Pid:  p.Pid,
		Name: n,
		CPU:  c,
		VMS:  m.VMS,
		RSS:  m.RSS,
		Swap: m.Swap,
	}, nil
}
开发者ID:nak3,项目名称:rkt,代码行数:22,代码来源:main.go


示例8: communicate

func (r region) communicate() {

	//collect region statistics
	ticker := time.NewTicker(5 * time.Second)

	//object holding process reference
	var exe *exec.Cmd
	exe = nil
	var start time.Time
	var proc *process.Process

	//process communication
	terminated := make(chan bool)

	for {
		select {
		case <-terminated:
			//the process exited for some Reason
			exe = nil
		case cmd := <-r.cmds:
			switch cmd.command {
			case "start":
				//if already running, exit
				if exe != nil {
					r.log.Error("Region is already running", r.UUID)
					continue
				}
				//execute binaries
				os.Chdir(r.dir)
				cmdName := "/usr/bin/mono"
				cmdArgs := []string{"OpenSim.exe", "-console", "rest"}
				exe = exec.Command(cmdName, cmdArgs...)
				err := exe.Start()
				if err != nil {
					errMsg := fmt.Sprintf("Error starting process: %s", err.Error())
					r.log.Error(errMsg)
					continue
				}
				r.log.Info("Started Successfully")
				start = time.Now()
				proc, _ = process.NewProcess(int32(exe.Process.Pid))
				go func() {
					//wait for process, ignoring process-specific errors
					_ = exe.Wait()
					r.log.Error("Terminated")
					exe = nil
					terminated <- true
				}()
			case "kill":
				//if not running, exit
				if exe == nil {
					errMsg := fmt.Sprintf("Kill region %v failed, region is not running", r.UUID.String())
					r.log.Error(errMsg)
					continue
				}
				if err := exe.Process.Kill(); err != nil {
					errMsg := fmt.Sprintf("Error killing process: %s", err.Error())
					r.log.Error(errMsg)
				}
			default:
				r.log.Info("Received unexpected command: %v", cmd.command)
			}
		case <-ticker.C:
			stat := mgm.RegionStat{UUID: r.UUID}
			if exe == nil {
				//trivially halted if we never started
				r.rStat <- stat
				continue
			}
			stat.Running = true

			cpuPercent, err := proc.CPUPercent(0)
			if err != nil {
				errMsg := fmt.Sprintf("Error getting cpu for pid: %s", err.Error())
				r.log.Error(errMsg)
			} else {
				stat.CPUPercent = cpuPercent
			}
			//memory info from this module may not be correct....
			memInfo, err := proc.MemoryInfo()
			if err != nil {
				errMsg := fmt.Sprintf("Error getting memory for pid: %s", err.Error())
				r.log.Error(errMsg)
			} else {
				stat.MemKB = (float64(memInfo.RSS) / 1024.0)
			}

			elapsed := time.Since(start)
			stat.Uptime = elapsed

			r.rStat <- stat
		}
	}
}
开发者ID:bitzend,项目名称:mgm,代码行数:94,代码来源:region.go



注:本文中的github.com/shirou/gopsutil/process.Process类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang event.Event类代码示例发布时间:2022-05-28
下一篇:
Golang process.NewProcess函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap