![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what is meaning of exit(0) and exit(1) | amitpansuria | UNIX for Dummies Questions & Answers | 1 | 08-28-2007 12:02 AM |
| exit 2 | xramm | Shell Programming and Scripting | 2 | 08-15-2007 06:48 AM |
| exit | dhananjaysk | Shell Programming and Scripting | 2 | 04-06-2006 05:34 AM |
| Where can I find a list of exit codes? (Exit code 64) | jkuchar747 | UNIX for Dummies Questions & Answers | 3 | 12-07-2004 03:08 PM |
| How to exit ssh | davidg | UNIX for Advanced & Expert Users | 1 | 10-16-2003 04:10 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
exit(0) versus exit(1)
What is the difference between using exit(0) and exit(1) to exit a program? Which should I use?
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
You normally use exit(0) if everything went ok. But if your program detects an error and decides to abort, you would use exit(1). Or you might use exit(1), exit(2), etc, with each exit code meaning some specific error.
|
|
#3
|
|||
|
|||
|
For normal exits use 0 (recommended)
and for abnormal program termination or incomplete ones use 1 (recommended) these exit status are indication to the environment from which the program has run about the status of exit of the program |
|
#4
|
|||
|
|||
|
What to do you want to tell your parent?
The rules is generally if all went went and you did what you were told (as all children should) then return 0. If something went wrong then return non-zero, preferably between 1 and 127. This is termed the exit code of a process and in a shell becomes the "$?" value. This allows you to do the following Code:
if myprogram
then
echo all went well
else
echo bad things
fi
|
|
#5
|
|||
|
|||
|
Thanks for the tips.
|
|
#6
|
|||
|
|||
|
hi enuenu,
actualy you should use #include <stdlib.h> exit(EXIT_SUCCESS); exit(EXIT_FAILURE); just my 2 cents |
|
#7
|
|||
|
|||
|
Thanks, I am still investigating (this and much more).
|
|||
| Google The UNIX and Linux Forums |