[Question] exec inside a goroutine


[Question] exec inside a goroutine

I wrote an app that terminates the browser after 10 minutes. I want to display a desktop notification using notify-send and os/exec. However the notification is never displayed. Here's the code

package main import ( "os/exec" "time" "http://ift.tt/2t3ZzrS; ) func main() { ticker := time.NewTicker(5 * time.Second) for range ticker.C { terminateBrowser() } } func terminateBrowser() { pids, _ := process.Pids() for _, pid := range pids { p, _ := process.NewProcess(pid) name, _ := p.Name() if name == "firefox" || name == "chrome" { go func(p *process.Process, name string) { time.Sleep(10 * time.Minute) p.Terminate() exec.Command("notify-send", name, name+" quit unexpectedly").Run() }(p, name) } } } 

Submitted July 16, 2017 at 07:26PM by newbgopher
via reddit http://ift.tt/2uo4NTg

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s