In the previous article, we already figured out how to terminate a container with a specific exit code.

To begin with, the return value must be smaller then `256`

. You can notice that:

- If you terminate the container with a code of
`0`

or some other positive number, then the same code will be sent to AppMaster. - If you terminate the container with a negative code, then another number will be sent to AppMaster.

This is because the Spring Boot Yarn works with exit code at a low level, and **two’s complement representation is used for negative exit codes**. Let’s take exit code = `-10`

for example.

Exit code value usually takes 1 byte. Now the following algorithm happens:

- The decimal number
`10`

is converted to binary. It will be`00001010`

; - Decimal
`-10`

would be`10001010`

in binary. Leftmost digit of the number indicates the sign.`1`

is minus,`0`

is plus; - This code in ones’ complement representation will be like this:
`11110101`

. Here we have inverted all the digits except for the signed one (leftmost); - This code in two’s complement representation will be like this:
`11110110`

. We just added`1`

.

In total, exit code = `-10`

, presented in two’s complement will be `11110110`

. **It looks strange that Spring Boot Yarn on the AppMaster side does not convert back from two’s complement to normal representation**. It simply converts the code to the decimal system. `11110110`

in binary will be `246`

in decimal.

It turns out that **if the container terminated with code **`-10`

**, the AppMaster will receive information that the container terminated with code **`246`

.

For simplicity, we can think of it like this: if we terminated the container with code `minus N`

, AppMaster will receive code `256 minus N`

.

If you still have any questions, feel free to ask me in the comments under this article, or write me on promark33@gmail.com.

If I saved your day, you can support me :)