func (c *Cmd) StopWithTimeout(to time.Duration) error {
	exited := make(chan bool)
	go func() {
		c.Wait()
		exited <- true
	}()

	ps, err := c.expandToChildProcesses(c.Process)
	if err != nil {
		return err
	}

	//signal all (child)processes to better simulate
	//shell behaviour
	for _, p := range ps {
		err := p.Signal(os.Interrupt)
		if err != nil {
			return err
		}
	}

	select {
	case <-exited:
		return nil //process exited by itself
	case <-time.After(to):
		for _, p := range ps {
			err := p.Kill()
			if err != nil {
				return err
			}
		}
		return nil
	}
}
//Attemps to gracefully shut down the process by first
//sending a interrupt signal and then wait the given amount
//for the process to shut down, if the process is still running
//kill it. @todo It will send a os.Interrupt signal which is not
//currently supported in windows
Attemps to gracefully shut down the process by first
sending a interrupt signal and then wait the given amount
for the process to shut down, if the process is still running
kill it. @todo It will send a os.Interrupt signal which is not
currently supported in windows
// Attemps to gracefully shut down the process by first // sending a interrupt signal and then wait the given amount // for the process to shut down if the process is still running // kill it . @todo It will send a os . Interrupt signal which is not // currently supported in windows
func (c *Cmd) StopWithTimeout(to time.Duration) error {
	exited := make(chan bool)
	go func() {
		c.Wait()
		exited <- true
	}()
	ps, err := c.expandToChildProcesses(c.Process)
	if err != nil {
		return err
	}
	for _, p := range ps {
		err := p.Signal(os.Interrupt)
		if err != nil {
			return err
		}
	}
	select {
	case <-exited:
		return nil 
	case <-time.After(to):
		for _, p := range ps {
			err := p.Kill()
			if err != nil {
				return err
			}
		}
		return nil
	}
}
func ( c * Cmd ) StopWithTimeout ( to time . Duration ) error { exited := make ( chan bool ) go func ( ) { c . Wait ( ) exited <- true } ( ) ps , err := c . expandToChildProcesses ( c . Process ) if err != nil { return err } for _ , p := range ps { err := p . Signal ( os . Interrupt ) if err != nil { return err } } select { case <- exited : return nil case <- time . After ( to ) : for _ , p := range ps { err := p . Kill ( ) if err != nil { return err } } return nil } }
Attemps to gracefully shut down the process by first
sending a interrupt signal and then wait the given amount
for the process to shut down, if the process is still running
kill it.
Attemps to gracefully shut down the process by first sending a interrupt signal and then wait the given amount for the process to shut down if the process is still running kill it .
//signal all (child)processes to better simulate //shell behaviour //process exited by itself