Hi, all.

I have some code:

...

func RunTimeout(c *exec.Cmd, cnl context.CancelFunc) error {
       defer cnl()
       if err := c.Start(); err != nil {
              return err
       }

       return c.Wait()
}

func main() {
       ctx, cnl := context.WithTimeout(context.Background(), 10*time.Second)

       if err := RunTimeout(exec.CommandContext(ctx, "test.sh"), cnl); err != 
nil {
              if err == context.DeadlineExceeded {
                     println("timed out")
              } else {
                     println(err.Error())
              }       
       }
}

Script *test.sh* looks like:
#!/bin/bash
sleep 60s


If exec.CommandContext timed out it would kill process. But in my case 
there are two process: parent bash process *test.sh* and its child process 
with *sleep 60s*. In this case only bash process *test.sh* will be killed 
after 10 seconds.

Is this normal behavior? It seems strange.

--
Best regards, Yuri

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to