since os/signal
is only for handling of incoming signals I’m asking if there is a native way to send signals to other processes?
Edit: The process I want to mange is nginx. My Go application should listen for some events and then send a SIGHUP
to nginx to reload its configuration
Advertisement
Answer
If you have created process with os.StartProcess or exec.Command you can use Process.Signal method:
cmd := exec.Command("CmdPath", "-param1", param1) cmd.Process.Signal(signal)
For external process You should know it’s process id (PID) and then call for example:
syscall.Kill(pid,syscall.SIGHUP)
Signal is a standart UNIX “kill” syscall, if you know a pid of the process, you can simply make a syscall with https://golang.org/pkg/syscall/#Kill