1819803 Members
2865 Online
109607 Solutions
New Discussion юеВ

Whats is exit code 255?

 
Sup
Advisor

Whats is exit code 255?

Hi,

We have C program running 24 hours. It exits with exit code 255. It is general exit code
i.e 255-128 = 127. Anybody know what is exact meaning of exit code 255/127? Is there any way to find out why process intermittently exiting with this code?
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: Whats is exit code 255?

If I were forced to guess, I would say that the code actually exited (or returned from main()) with -1 (0xFFFF). Which to the shell (limited to 8 bits) looks like 255.

The convention is for the program to exit with 0 (good) or errno (bad) but your giy didn't do that. The bottom line is that the returned result means just what the programmer intended - nothing more or nothing less.


If it ain't broke, I can fix that.
Sup
Advisor

Re: Whats is exit code 255?

Hi,

I forgot to mention, This process exits with 255 is a child process. The child sending 255 exit code to parent ( SIGCHLD handler ) and parent printing this number. We get exit code in SIGCHLD handler as below

child_hdlr()
{
process = wait(&status);
exit_code=WEXITSTATUS( status );
}
A. Clay Stephenson
Acclaimed Contributor

Re: Whats is exit code 255?

I now see your problem. You are putting the wait inside a SIGCHLD signal handler. At that point the child has already exited so the wait() system call isn't waiting on anything.
If it ain't broke, I can fix that.