Nov 12, 2019

[Go] signal passing through channel implement differently on each platform

Reference: 
https://groups.google.com/forum/#!msg/golang-nuts/J5SXvinQTFE/FiCJPAV8BAAJ

futex:
http://vsdmars.blogspot.com/2019/03/futex-futex-skim-through.html

Below the program crashes at Darwin while OK under Linux.
This is due to Darwin is using pipe to (which opens up the minimum fd, i.e 3)
and Linux is using futex for the signal event passing. (which is fast)


Do NOT open random fd and manipulate with it unless you know the program logic~
package main

import (
        "os"
        "os/signal"
)

func main() {
        sigs := make(chan os.Signal)
        signal.Notify(sigs, os.Interrupt)

        if f := os.NewFile(3, ""); f != nil {
                f.Close()
        }

        <-sigs
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.