The exit value bit size

The exit status is an 8-bit integer; this means that even if the argument for the Go function is an integer, then the status that is returned will be the result of a modulo operation between the passed value and 256.

Let's take a look at the following program:

package main

import (
"fmt"
"os"
)

func main() {
fmt.Println("Hello, playground")
os.Exit(-1)
}

The full example is available at https://play.golang.org/p/vzwI1kDiGrP. 

This will have an exit status of 255 even if the function argument is -1 because (-1)%256=255. This happens because the exit code is an 8-bit number (0, 255). 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.255.168