I made program in Go that kills a process with syscall.Kill()
But if I daeminze that process with fork()
+ setsid()
then syscall.Kill()
does not kill that process.
If I use shell kill
then I'm able to kill that process in both cases.
I tried different signals: SIGINT
, SIGTERM
and SIGKILL
buthey do not kill the daemon.
Daemonizing a Go process using syscalls is not currently possible to do reliably and that's why your sort-of-daemonized process was impossible to kill: it has been wedged (though I should admit it's weird why it did not die in response to sending SIGKILL
which makes the kernel just destroy the process, no signal delivery is attempted).
To properly daemonize a Go process one is advised to use a wrapper process (such as daemon
) or run it under an an advanced substitute for the init
superserver such as systemd
or upstart
or a standalone supervisor such as runit
, monit
and others—in which case the process has no braindead requirement to be a true Unix daemon and may behave like a normal process: does not perform double-fork
+setsid
trickery, does not mess with PID file management, is able to write to its regular I/O streams etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With