代码拉取完成,页面将自动刷新
同步操作将从 John/gf 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// 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"
"fmt"
"os/exec"
"errors"
)
// 子进程
type Process struct {
exec.Cmd
Manager *Manager // 所属进程管理器
PPid int // 自定义关联的父进程ID
}
// 开始执行(非阻塞)
func (p *Process) Start() (int, error) {
if p.Process != nil {
return p.Pid(), nil
}
if p.PPid > 0 {
p.Env = append(p.Env, fmt.Sprintf("%s=%d", gPROC_ENV_KEY_PPID_KEY, p.PPid))
}
if err := p.Cmd.Start(); err == nil {
if p.Manager != nil {
p.Manager.processes.Set(p.Process.Pid, p)
}
return p.Process.Pid, nil
} else {
return 0, err
}
}
// 运行进程(阻塞等待执行完毕)
func (p *Process) Run() error {
if _, err := p.Start(); err == nil {
return p.Wait()
} else {
return err
}
}
// PID
func (p *Process) Pid() int {
if p.Process != nil {
return p.Process.Pid
}
return 0
}
// 向进程发送消息
func (p *Process) Send(data []byte) error {
if p.Process != nil {
return Send(p.Process.Pid, data)
}
return errors.New("invalid process")
}
// Release releases any resources associated with the Process p,
// rendering it unusable in the future.
// Release only needs to be called if Wait is not.
func (p *Process) Release() error {
return p.Process.Release()
}
// Kill causes the Process to exit immediately.
func (p *Process) Kill() error {
if err := p.Process.Kill(); err == nil {
if p.Manager != nil {
p.Manager.processes.Remove(p.Pid())
}
return nil
} else {
return err
}
}
// Signal sends a signal to the Process.
// Sending Interrupt on Windows is not implemented.
func (p *Process) Signal(sig os.Signal) error {
return p.Process.Signal(sig)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。