-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (30 loc) · 839 Bytes
/
main.go
File metadata and controls
38 lines (30 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
)
var (
cores int
duration int
)
func main() {
start := time.Now()
flag.IntVar(&cores, "c", 1, "-c <number-of-cores>")
flag.IntVar(&duration, "t", 60, "-t <duration-in-seconds>")
flag.Parse()
log.Printf("Starting the task on %d cores and running it for %d seconds\n", cores, duration)
Run(cores)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
select {
case <-time.After(time.Duration(duration) * time.Second):
log.Printf("Task timeout after %d seconds!", duration)
case <-c:
log.Printf("Task cancelled after %d milliseconds!\n", (time.Now().UnixNano()-start.UnixNano())/1e6)
}
log.Printf("Task finished - Worked for %d milliseconds!\n", (time.Now().UnixNano()-start.UnixNano())/1e6)
}