Last active
March 23, 2017 07:52
-
-
Save felixge/c34e11269838dc169376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd := exec.Command("/bin/sh", "-c", "watch date > date.txt") | |
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} | |
start := time.Now() | |
time.AfterFunc(3*time.Second, func() { | |
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) | |
}) | |
err := cmd.Run() | |
fmt.Printf("pid=%d duration=%s err=%s\n", cmd.Process.Pid, time.Since(start), err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run example3.go | |
pid=41352 duration=3.001809822s err=signal: killed | |
$ ps -j | |
USER PID PPID PGID SESS JOBC STAT TT TIME COMMAND | |
felix 41008 41002 41008 0 0 Ss s000 0:00.14 -/bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment