Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 593 Bytes

README.md

File metadata and controls

28 lines (23 loc) · 593 Bytes

command

os/exec的简易封装,防止出现孤儿进程

使用示例

执行相应指令

command.ExecCommand("ebook-convert", []string{"1.txt","1.pdf"}, 30*time.Minute)

关闭可能存在的孤儿进程

...
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
    s := <-c
    fmt.Println("get signal:", s)
    fmt.Println("close child process...")
    command.CloseChildProccess()
    fmt.Println("close child process done.")
    fmt.Println("exit.")
    os.Exit(0)
}()
...