2018-05-09 18:29:46 +08:00
|
|
|
// Copyright 2018 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://gitee.com/johng/gf.
|
|
|
|
|
|
|
|
// 进程管理.
|
|
|
|
package gproc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2018-05-10 16:07:14 +08:00
|
|
|
"gitee.com/johng/gf/g/util/gconv"
|
2018-05-09 18:29:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-05-10 16:07:14 +08:00
|
|
|
gPROC_ENV_KEY_PPID_KEY = "gproc.ppid"
|
2018-05-09 18:29:46 +08:00
|
|
|
)
|
|
|
|
|
2018-05-10 16:07:14 +08:00
|
|
|
// 获取当前进程ID
|
|
|
|
func Pid() int {
|
|
|
|
return os.Getpid()
|
2018-05-09 18:29:46 +08:00
|
|
|
}
|
|
|
|
|
2018-05-10 16:07:14 +08:00
|
|
|
// 获取父进程ID
|
|
|
|
func Ppid() int {
|
|
|
|
return gconv.Int(os.Getenv(gPROC_ENV_KEY_PPID_KEY))
|
2018-05-09 18:29:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 判断当前进程是否为gproc创建的子进程
|
|
|
|
func IsChild() bool {
|
2018-05-10 16:07:14 +08:00
|
|
|
return os.Getenv(gPROC_ENV_KEY_PPID_KEY) != ""
|
2018-05-09 18:29:46 +08:00
|
|
|
}
|
|
|
|
|