Operating System - Linux
1753808 Members
7975 Online
108805 Solutions
New Discussion юеВ

Re: Exit status code 0377 (255 or -1)

 

code 0377

gdb reports statement(program exited with code 0377)

Somebody knows the reason of this problem?
Thanks in advance!
3 REPLIES 3
Peter Godron
Honored Contributor

Re: code 0377

Subrat,
this could be down to unhandled error condition. 0377oct is 255dec, which could be interpreted as -1.

If this is a C program add an atexit function, which is defined in stdlib.h.

Then debug you program, and watch for return codes from called functions.

Please keep us updated.
A. Clay Stephenson
Acclaimed Contributor

Re: code 0377

Every program exits with a status either explicitly with an exit(status) statement or a return(status) from main. The exception to this is if main does not return a value or no exit was called; in that case, the value returned to the system is undefined. By convention, an exit status of zero indicates that all was well.

In your particular case, it appears that an error condition was detected and exit was called with a value of 0377 octal so that if you did an "echo ${?}" immediately after the program terminated, you would see 255. Man 2 exit for details.

This problem should not be considered a program crash since it appears that the program itself detected an abnormal condition and terminated. You really have to inspect the source code to find what would cause an exit with a status of 0377. 0377 only has meaning to those who wrote the program. It's a little surprising that the program was smart enough to detect this condition but sloppy enough not to report some sort of error message on stderr -- or did you leave that part out?
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: Exit status code 0377 (255 or -1)

>Clay: in that case, the value returned to the system is undefined

For C99 and C++ the Standards says it returns 0. HP's C compiler should now do that by default.
But unless you know you are using C99, you should do an explict return of 0 for C.