Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to `syscall.Kill()` a daemonized Go process

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.

like image 566
Eugene Avatar asked Apr 11 '14 16:04

Eugene


1 Answers

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.

like image 130
kostix Avatar answered Nov 14 '22 22:11

kostix