Goverwatch
Golang file watcher
Specify a command to execute and a list of files to watch on.
If one of the file is modified, your command will be re-executed.
It is useful in a development environment to have hot reloading.
echo "trigger watcher" > test.txt
go run main.go -c "go build main.go" -files test.txt
go run goverwatch.go -c "go run test/server.go" -files "*/*.go"
Processes
cmd.Start()
will create a child process.
If you use the Kill()
function it will kill this process but not his childrens.
His childrens will then be sons of INIT (PID 1) which can lead to unwanted scenarios.
To prevent that we are using process group in order to kill process and all of his childrens.
To kill this process and his childrens we have to add them in the same process group.
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
We can then kill every process in the group by passing a negative integer to the Kill()
function.
syscall.Kill(-runningProcess.Pid, syscall.SIGKILL)