Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined: syscall.SIGURG on a working code

I am new to go currently trying to understand some code wrote by a coworker

go func() {
    s := <-sigs
    if s == syscall.SIGURG {
        fmt.Println("received sigur")
    } else {
        log.Printf("RECEIVED SIGNAL: %s", s)
        os.Exit(1)
    }
}()

I used both GoLand & VSCode and those two IDE report an error on if s == syscall.SIGURG { They throw undefined: syscall.SIGURG

The thing is, I know this code works on Debian. So I'm trying why it's not working on my Windows computer

I have the required imports though :

import ( 
    "fmt"
    "os"
    "os/signal"
    "syscall"
)
like image 624
Thryn Avatar asked Nov 16 '25 18:11

Thryn


1 Answers

As @Volker wrote in a comment, SIGURG does not exist on Windows. It exists on Unix-like systems, like Debian.

I believe if you change the code to use golang.org/x/sys/unix instead of syscall, the behavior would be much more obvious to you. The Golang documentation for the syscall package has the following deprecation notice:

Deprecated: this package is locked down. Callers should use the corresponding package in the golang.org/x/sys repository instead. That is also where updates required by new systems or versions should be applied. See https://golang.org/s/go1.4-syscall for more information.

There is also the package golang.org/x/sys/windows for Windows, and it does not include SIGURG, because it does not exist on Windows.

like image 142
jakub Avatar answered Nov 18 '25 21:11

jakub