Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does exit code 6 generally mean in c?

Tags:

c

I just need the general meaning of it to work out a crash. Theirs nothing about it anywhere else that I could find.

like image 790
michael lee Avatar asked Mar 25 '17 07:03

michael lee


People also ask

What are exit codes in C?

The purpose of the exit() function is to terminate the execution of a program. The “return 0”(or EXIT_SUCCESS) implies that the code has executed successfully without any error. Exit codes other than “0”(or EXIT_FAILURE) indicate the presence of an error in the code.

What do exit codes mean?

An exit code is a system response that reports success, an error, or another condition that provides a clue about what caused an unexpected result from your command or script. Yet, you might never know about the code, because an exit code doesn't reveal itself unless someone asks it to do so.

What is normal exit code?

An exit code, or sometimes known as a return code, is the code returned to a parent process by an executable. On POSIX systems the standard exit code is 0 for success and any number from 1 to 255 for anything else. Exit codes can be interpreted by machine scripts to adapt in the event of successes of failures.

What is exit code 11 in C?

Under Linux and most other Unix variants, the signal number 11 indicates a segmentation fault, as remarked by Kerrek SB.


2 Answers

Programs dying due to POSIX signal SIGABRT exit with an error code of 6 and the highest bit set.

SIGABRT is caused by calling abort() which might be due to an assertion failing.

If the highest bit isn't set, it's an application-specific error code. You can type echo $? into your shell to see what error code the application right before exited with.

like image 76
a3f Avatar answered Oct 27 '22 00:10

a3f


Regarding the C main function, there is no general standard of exit codes. It is a convention that a program returns 0 if it has been done successful and everything else otherwise. But even this is rather a thumb rule.

A specific application may have specific return codes which hopefully are documented somewhere.

After digging a little bit deeper I found exit (cppreference.com). I consider this because exit() is the other possibility to leave an application and I'm quite sure that the passed exit value is processed the same way like the return value of main().

It mentions EXIT_SUCCESS and EXIT_FAILURE:

control is returned to the host environment. If exit_code is zero or EXIT_SUCCESS, an implementation-defined status, indicating successful termination is returned. If exit_code is EXIT_FAILURE, an implementation-defined status, indicating unsuccessful termination is returned. In other cases implementation-defined status value is returned.

On this site, there are also links to the respective C standards.

A similar statement can be found in the Linux man page of exit:

The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE, that may be passed to exit() to indicate successful or unsuccessful termination, respectively.

like image 35
Scheff's Cat Avatar answered Oct 26 '22 23:10

Scheff's Cat