zoukankan      html  css  js  c++  java
  • 1.9 进程pid,运行耗时 运行退出状态

    package main
    
    import (
    	"fmt"
    	"os/exec"
    	"runtime"
    	"time"
    )
    
    func main() {
    
    	var cmd string
    	if runtime.GOOS == "windows" {
    		cmd = "timeout"
    	} else {
    		cmd = "sleep"
    	}
    
    	proc := exec.Command(cmd, "1")
    	proc.Start()
    
    	// Wait function will
    	// wait till the process ends.
    	proc.Wait()
    
    	// After the process terminates
    	// the *os.ProcessState contains
    	// simple information
    	// about the process run
    	fmt.Printf("PID: %d
    ", proc.ProcessState.Pid())
    	fmt.Printf("Process took: %dms
    ", proc.ProcessState.SystemTime()/time.Microsecond)
    	fmt.Printf("Exited sucessfuly : %t
    ", proc.ProcessState.Success())
    }
    
    /*
    PID: 6337
    Process took: 755ms
    Exited sucessfuly : true
    */
    
    package main
    
    import (
    	"fmt"
    	"os/exec"
    	"runtime"
    )
    
    func main() {
    
    	var cmd string
    	if runtime.GOOS == "windows" {
    		cmd = "timeout"
    	} else {
    		cmd = "sleep"
    	}
    	proc := exec.Command(cmd, "1")
    	proc.Start()
    
    	// No process state is returned
    	// till the process finish.
    	fmt.Printf("Process state for running process: %v
    ", proc.ProcessState)
    
    	// The PID could be obtain
    	// event for the running process
    	fmt.Printf("PID of running process: %d
    
    ", proc.Process.Pid)
    }
    
    /*
    Process state for running process: <nil>
    PID of running process: 6410
    
    */
    
  • 相关阅读:
    第二次公共考试,判断错题集
    云助理里面查询渠道的方法
    公司第二阶段公共考试题
    云助理绑定手机及密码找回方法
    oracle的卸载
    pl/sql进阶--例外处理
    oracle--dba和表的备份与恢复
    oracle触发器
    oracle视图
    pl/sql的介绍
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8593254.html
Copyright © 2011-2022 走看看