os: Document Exit() behavior with code outside 0 - 255 #30959
Labels
Documentation
Issues describing a change to documentation.
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Compile program then run:
What did you expect to see?
./main should return failure code
is printed in terminal.What did you see instead?
No output.
The number
256
is passed as-is to_exit()
, or in my caseexit_group()
on Linux.But on Linux, and other systems which use traditional
wait*()
system call, only the lower 8 bits of that number are available to the parent. it means the program above appears as success.If the parent uses
waitid()
, the number won't be truncated and return as-is to the parent (Though not on Linux, which still truncate the number evenwaitid()
was used. The behavior maybe change in the future).So the behavior of
os.Exit(code)
where code > 255 or code < 0 can not be consistent. I propose one of these changes:Always transform the code like
wait*()
does, mean a value between 0-255 always returns to parent.Limit the code to value between 0 - 255, do something in case the code out of range:
Document that only value between 0 - 255 is consistent and should be used. Value greater than 255 may or may not be truncated, so the exit code is unspecified.
The text was updated successfully, but these errors were encountered: