The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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 03:02 AM
exit 2 xramm Shell Programming and Scripting 2 08-15-2007 09:48 AM
exit dhananjaysk Shell Programming and Scripting 2 04-06-2006 08:34 AM
Where can I find a list of exit codes? (Exit code 64) jkuchar747 UNIX for Dummies Questions & Answers 3 12-07-2004 06:08 PM
How to exit ssh davidg UNIX for Advanced & Expert Users 1 10-16-2003 07:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-02-2007
enuenu enuenu is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 39
exit(0) versus exit(1)

What is the difference between using exit(0) and exit(1) to exit a program? Which should I use?
  #2 (permalink)  
Old 06-02-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 06-02-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
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 (permalink)  
Old 06-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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 (permalink)  
Old 06-02-2007
enuenu enuenu is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 39
Thanks for the tips.
  #6 (permalink)  
Old 06-16-2007
grumpf grumpf is offline
Registered User
  
 

Join Date: May 2006
Posts: 101
hi enuenu,
actualy you should use


#include <stdlib.h>

exit(EXIT_SUCCESS);
exit(EXIT_FAILURE);


just my 2 cents
  #7 (permalink)  
Old 06-17-2007
enuenu enuenu is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 39
Thanks, I am still investigating (this and much more).
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0