Created
May 30, 2016 13:53
-
-
Save samuell/5d8de4e184e6055248cc23c20d872166 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
package main | |
import ( | |
"bytes" | |
"fmt" | |
"os/exec" | |
"sync" | |
) | |
func main() { | |
wg := new(sync.WaitGroup) | |
for i := 0; i < 5000; i++ { | |
wg.Add(1) | |
go func(i int) { | |
fmt.Println("Starting sleep ", i, "...") | |
cmd := exec.Command("sleep", "3600") | |
cmdOut := &bytes.Buffer{} | |
cmd.Stdout = cmdOut | |
err := cmd.Start() | |
if err != nil { | |
panic(err) | |
} | |
cmd.Wait() | |
fmt.Println("Finishing sleep ", i, "...") | |
wg.Done() | |
}(i) | |
} | |
fmt.Println("Waiting for WaitGroup ...") | |
wg.Wait() | |
fmt.Println("WaitGroup finished!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment