Vishnu
Vishnu

Reputation: 4677

golang handling kill in a process started by cmd.Start

I have two go programs. ProgA starts ProgB using cmd.Start(). From ProgA I try to kill ProgB, but ProgB shouldn't get killed immediately, it has to do some cleanup before dying. So I'm using signal.Notify in ProgB to handle sigcall.SIGKILL but whenever ProgA calls progb.Process.Kill() it doesn't seem to notify ProgB(write contents to sigc channel)

in ProgB I have the notify like this:

signal.Notify(sigc, syscall.SIGKILL)
go func() {
            fmt.Println("started listening")
            <-sigc
            fmt.Println("sig term")
            cleanUp()
            os.Exit(1)   
            
}()
someLongRunningCode() 

is there something I'm missing out? I'm sure that ProgA sends a SIGKILL because cmd.Process.Kill() internally does a process.Signal(SIGKILL)

Upvotes: 1

Views: 1171

Answers (1)

mechmind
mechmind

Reputation: 1767

SIGKILL cannot be trapped by recieving process - kernel will force process termination. You may send SIGTERM to process and handle it on other side - it is a conventional method to stop an application.

Upvotes: 7

Related Questions