go - Wait for a non child Process to end -
hi working on simple code monitor process , restart process in case process crashes. have written small sample code.
this external process
package main import ( "fmt" "time" ) func main() { { time.sleep(1000 * time.millisecond) fmt.println("hello") } }
this code monitors it.
package main import ( "fmt" "os" ) func main() { p, e := os.findprocess(<processid>) fmt.println(e) fmt.println(p.wait()) fmt.println("done") }
the challenge here since first process not child process of second one, not wait , directly exits. please let me know if has ideas around this.
thanks.
monitoring process exits because p.wait()
not block.
from docs:
on operating systems, process must child of current process or error returned.
you can perhaps poll process pool check if process still exists.
Comments
Post a Comment