cmd := exec.Command("")
//这几天再使用cmd的时候,发现内存占有过高,就top了一下,无意发现了很多僵尸进程
//所谓的僵尸进程就是父进程一直在运行,子进程结束后,没有被回收
//代码里
cmd.Start()
cmd.Run()
// 这两个都有在用,以为这是阻塞和不阻塞的问题, 当我用到了start的时候,就暴露出了这个问题,太多的僵尸进程了
// 进去一看start的注释
// The Wait method will return the exit code and release associated resources
// once the command exits.
//人都傻了,需要调用wait回收
//run为何不需要呢,一看代码,人又傻了,居然在里面封装了wait的调用
//func (c *Cmd) Run() error {
// if err := c.Start(); err != nil {
// return err
//}
// return c.Wait()
//}
//所以在实现前,还是好好看下注释和代码吧
//wait会阻塞的,不想阻塞又得回收这个就这样写吧
//cmd := exec.Command("")
//err = cmd.Start()
//if err != nil {
// return
//}
//go func(cmd *exec.Cmd) {
// if errIgnore := cmd.Wait(); errIgnore != nil {
// conf.Logger.Error("start spider wait err", "err", errIgnore)
// }
//}(cmd)
//return
//cmd.CombinedOutput() 获取输出并 wait