Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The return code of an application is an int16_t?

When talking about starting a new process, you can do it using int system(char* command). If you pass an non NULL parameter, you can get:

  • -1 if the child process cannot be started;
  • a return code of the child process otherwise;

note: in Unix/Linux the return code is located on the higher eight bits of the result, while the lower eight bits contain the termination reason code>{1}<, so a retcode equal to 1 will be returned as 256; you can get the actual return code by shifting the value eight bits to the right; there is also a macro named WEXITSTATUS() that does it for you.

Searching for the implementation of WEXITSTATUS() it's a shift 8 bits to the right.

#define WEXITSTATUS(x) (_W_INT(x) >> 8)

This is the reason why I tend to think that return codes are 2 bytes (and also from >{1}<). The quote is from a C course found online.

P.s I would like to know the difference between the return code and termination reason code, aren't they the same?

like image 767
Cătălina Sîrbu Avatar asked Jan 07 '21 11:01

Cătălina Sîrbu


People also ask

What is int16_t in Arduino?

Suppose a sensor uses a 16-bit integer or you want to create an integer that is always 16-bit. That is when the "int16_t" is used. It is always 16 bits on all Arduino boards.

What are the return codes for patch install issues?

As an example return code 0 is success and return code 3010 is reboot required, but there are many other codes that can help troubleshoot patch install issues. This isn't a comprehensive list. Our suggestion is to use your favorite search tool if the code isn't listed here. For instance, the return code 2147483647 isn't listed here.

How do I use error codes in my application?

Use a non-zero number to indicate an error. In your application, you can define your own error codes in an enumeration, and return the appropriate error code based on the scenario. For example, return a value of 1 to indicate that the required file is not present and a value of 2 to indicate that the file is in the wrong format.

How many int16_t in 65/536 uint16_t?

That is mapping 65,536 uint16_tinto 65,535 int16_t. Something is missing. – chux - Reinstate Monica Jun 1 '17 at 19:50


1 Answers

There s different reasons for termination:

  • process terminates calling return (explicitly or not)
  • process terminates after signal delivery
  • process stopped after signal delivery. This one is not really termination but need to be caught in many situations.

For each of theses terminations a code is accessible, respectively:

  • value returned (only low eight bits of it)
  • signal number
  • signal number
like image 163
Jean-Baptiste Yunès Avatar answered Oct 10 '22 14:10

Jean-Baptiste Yunès