简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM