how to ignore SIGHUP signal

2,245 views
Skip to first unread message

davy zhang

unread,
Jul 1, 2013, 5:06:44 AM7/1/13
to golan...@googlegroups.com
I have a server don't wanna quit when close the terminal

so I need to ignore the sighup signal

but all I found is the articles of how to handle it

thanks

Eric Palmer

unread,
Jul 1, 2013, 5:23:39 AM7/1/13
to davy zhang, golang-nuts
What about starting it with nuhup

At least on linux and mac you can do that.



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
KK4MWM (Ham Radio)
About Me
http://www.thingiverse.com/DaddyOh
Join the 3DPrinter Revolution
http://makerbot.com

davy zhang

unread,
Jul 1, 2013, 5:28:58 AM7/1/13
to golan...@googlegroups.com, davy zhang, er...@ericfpalmer.com
I know I can use nohup command, but this program is used by others, some carefulness system admin might forget to use nohup
and yes ,I can write a script to start to program
but some sa might forget use that script too :D

In Python there's simple to do this, and I always did add this line :

 signal.signal(signal.SIGHUP, signal.SIG_IGN)

I don't know if golang has such

davy zhang

unread,
Jul 1, 2013, 5:29:09 AM7/1/13
to golan...@googlegroups.com, davy zhang, er...@ericfpalmer.com
I know I can use nohup command, but this program is used by others, some carefulness system admin might forget to use nohup
and yes ,I can write a script to start to program
but some sa might forget use that script too :D

In Python there's simple to do this, and I always did add this line :

 signal.signal(signal.SIGHUP, signal.SIG_IGN)

I don't know if golang has such


On Monday, July 1, 2013 5:23:39 PM UTC+8, Eric Palmer wrote:

m...@ebfe.org

unread,
Jul 1, 2013, 5:39:59 AM7/1/13
to davy zhang, golan...@googlegroups.com
On Mon, Jul 01, 2013 at 02:06:44AM -0700, davy zhang wrote:
> I have a server don't wanna quit when close the terminal
>
> so I need to ignore the sighup signal

something like:

package main

import (
"fmt"
"os"
"os/signal"
"syscall"
)

func main() {
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Signal(syscall.SIGHUP))
for {
<-ch
fmt.Println("SIGHUP")
}
}()

/* ... */
}


should work.

davy zhang

unread,
Jul 1, 2013, 11:41:26 PM7/1/13
to golan...@googlegroups.com, davy zhang, m...@ebfe.org
Thanks ! this worked!

Thomas Bushnell, BSG

unread,
Jul 8, 2013, 12:45:43 PM7/8/13
to davy zhang, golang-nuts, er...@ericfpalmer.com
This seems to be an oversight; I wonder what the main Go devs think.

The generic os/signal package provides only signal catching. In Unix however, you can also block and ignore signals. There is a difference between ignoring a signal (which takes place in the kernel) and catching it but doing nothing (which is what mg's solution does). Likewise, blocking is quite different from catching and then dealing with it later. In addition, you can restore the original default behavior for a signal if you've been catching or ignoring it. (Note that it is not possibly to correctly emulate the default behavior with a handler.)

Go handles catching of signals with a special assembly shim, which is necessary because it has its own stack discipline and so forth, and there are good reasons that os/signal shouldn't have Unix-specific things like blocking or ignoring signals. But the syscall package certainly should provide those interfaces, and AFAICT does not.

Thomas

Reply all
Reply to author
Forward
0 new messages