Skip to contentSkip to conversation

exit(42)

DISCUSSION Ankit Jain 9 participants 10 messages Sep 24, 2004 – Sep 27, 2004

lore
Share & tools
lore

Ankit Jain

author
#0 lore raw

well do any body know what does this mean?

exit(42)

and also when we say exit(0) or exit(1) then there is anyway to catch these values

also when we return from main fn then what is the
benfit?

does it have any utilisation?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html

#1 lore raw
Quoted 3 lines · On Fri, 24 Sep 2004 12:57:59 +0100 (BST) Ankit Jain <[email protected]>…

well do any body know what does this mean?

exit(42)

It mean - "No message of desired type",

Quoted 21 lines

and also when we say exit(0) or exit(1) then there is anyway to catch these values

also when we return from main fn then what is the
benfit?

does it have any utilisation?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Alphex Kaanoken,
Senior Developer of
Crew IT research labs.
Web: http://crew.org.ru
Mail: kaanoken at crew.org.ru
#2 lore raw
In reply to Ankit Jain

it does have a benefit....
it could be useful to another app that is trying to check the return value or exit status of your application

like in bash programming... many bash scripts rely on the exit values of programs...

Quoted 26 lines · Ankit Jain

well do any body know what does this mean?

exit(42)

and also when we say exit(0) or exit(1) then there is anyway to catch these values

also when we return from main fn then what is the
benfit?

does it have any utilisation?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to Ankit Jain

Operating systems can catch programs exit values (eg: by exit() in C/C++).

So, you can do it by script shell (in UNIX) or by "DOS" commands in Wndows Console. Well, Operating systems can also give you this values when you call a program from another program, see exec() and system() functions.

Luciano

Quoted 26 lines · Ankit Jain

well do any body know what does this mean?

exit(42)

and also when we say exit(0) or exit(1) then there is anyway to catch these values

also when we return from main fn then what is the
benfit?

does it have any utilisation?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to Ankit Jain

On Fri, 2004-09-24 12:57:59 +0100, Ankit Jain <[email protected]> wrote in message <[email protected]>:

Quoted 3 lines

well do any body know what does this mean?

exit(42)

It just leaves 42 (Illuminati!) back to the caller.

Quoted 2 lines

and also when we say exit(0) or exit(1) then there is anyway to catch these values

Normally, you use a return value of zero to signal "Success!" and anything else for "Something undesired happened."

Quoted 2 lines

also when we return from main fn then what is the
benfit?

exit() just here ends the program, possibly internally calling some cleanup functions and the like. Return does only end a program IFF it returns from the main() function.

Quoted 1 line

does it have any utilisation?

It does! Remember, exit() is "stop it here", while return is only "stop it here, if I'm in main()." See the difference? If, at some later time, the whole program gets integrated into the codebase of a larger scale program, where the former main() call just does one part of the work, exit() from the old main() wouldn't be a nice thing:-)

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#8 lore raw
In reply to Ankit Jain
Quoted 4 lines · Ankit Jain

well do any body know what does this mean?

exit(42)

It means return value 42 as the exit value for the program. Every program returns an exit value (integer) when it exits. 0 means not error, anything else is an error value and the specific number can mean the type of error if its documented and the caller knows what to expect.

Quoted 3 lines

and also when we say exit(0) or exit(1) then there is anyway to catch these values

From the caller you can catch this value, read the documentation for your shell about the return value. I think its $? under bash.

Quoted 5 lines

also when we return from main fn then what is the
benfit?

does it have any utilisation?

main is just another function almost like any other in your program. The system doesn't look for the function main to run, its just a convention used by c (in windows the main function is called winmain for example, don't remember what its called in pascal, but IIRC something different also).

when you compile your program its linked with some assembler code that handles setting up you environment. The system looks for a symbol in your program called _start and start the execution from there. This function is responsible for setting everything up, including argc and argv (the command line arguments and environment variables) and possibly handling calling constructors of global classes in c++ (not sure about that though). It then calls your main function with the proper values of argc and argv.

When you main function returns, or when you call exit, a function called exit is called which handles all the cleaning up of your program and then the function _exit is called to finish exiting the program. You are not supposed to call _exit directly since it bypasses cleaning up, calling it directly is only useful if you use vfork where you don't want any cleaning up done since it messes things up (you shouldn't use vfork for most things nowadays since fork has almost no more overhead. If you don't know you need it, then you don't).

Quoted 17 lines

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

+++++++++++++++++++++++++++++++++++++++++++
This Mail Was Scanned By Mail-seCure System
at the Tel-Aviv University CC.

#9 lore raw
Quoted 58 lines · --- Micha Feigin
Quoted 4 lines · Ankit Jain

well do any body know what does this mean?

exit(42)

It means return value 42 as the exit value for the program. Every
program returns an exit value (integer) when it exits. 0 means not
error, anything else is an error value and the specific number can mean
the type of error if its documented and the caller knows what to expect.

Quoted 1 line

and also when we say exit(0) or exit(1) then there

is

Quoted 2 lines

anyway to catch these values

From the caller you can catch this value, read the documentation for
your shell about the return value. I think its $? under bash.

Quoted 5 lines

also when we return from main fn then what is the
benfit?

does it have any utilisation?

main is just another function almost like any other in your
program. The system doesn't look for the function main to run, its just
a convention used by c (in windows the main function is called winmain
for example, don't remember what its called in pascal, but IIRC
something different also).

when you compile your program its linked with some assembler code that
handles setting up you environment. The system looks for a symbol in
your program called _start and start the execution from there. This
function is responsible for setting everything up, including argc and
argv (the command line arguments and environment variables) and possibly
handling calling constructors of global classes in c++ (not sure about
that though). It then calls your main function with the proper values
of argc and argv.

Quoted 23 lines

When you main function returns, or when you call exit, a function called
exit is called which handles all the cleaning up of your program and
then the function _exit is called to finish exiting the program. You
are not supposed to call _exit directly since it bypasses cleaning up,
calling it directly is only useful if you use vfork where you don't
want any cleaning up done since it messes things up (you shouldn't use
vfork for most things nowadays since fork has almost no more
overhead. If you don't know you need it, then you don't).

Quoted 5 lines

thanks

ankit

________________________________________________________________________

Quoted 14 lines
Quoted 5 lines

Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line

"unsubscribe linux-c-programming" in

Quoted 2 lines

the body of a message to [email protected] More majordomo info at

http://vger.kernel.org/majordomo-info.html

Quoted 5 lines

+++++++++++++++++++++++++++++++++++++++++++
This Mail Was Scanned By Mail-seCure System
at the Tel-Aviv University CC.

Quoted 7 lines

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html

this could also be the reason:
if we r working with child and parent procees then as child get terminated it has to pas some status to the parent that is going to exit then by using exit(42) child give information to the parent that it is goig to exit now having status 42.

thanx

_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

#3 lore raw
In reply to Ron Michael Khu

hi,
I guess the value is stored in a global var called "errno".

Pankaj

Quoted 8 lines · Ron Michael Khu
Quoted 3 lines

linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Only one man in a thousand is a leader of men
Remaining 999 follow women.
#4 lore raw
Quoted 3 lines · Pankaj

hi,
I guess the value is stored in a global var called "errno".

If this is about the return value, it is not stored in errno. errno stores the error value of system calls. If errno is set then the process wasn't executed at all.

To find the return value in c, you can use waitpid and then WEXITSTATUS(status).

Quoted 23 lines

Pankaj

Quoted 8 lines · Ron Michael Khu
Quoted 3 lines

linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 10 lines
Only one man in a thousand is a leader of men
Remaining 999 follow women.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
 
 +++++++++++++++++++++++++++++++++++++++++++
 This Mail Was Scanned By Mail-seCure System
 at the Tel-Aviv University CC.
#5 lore raw
Quoted 5 lines · Micha Feigin
Quoted 2 lines · Pankaj

hi,
I guess the value is stored in a global var called "errno".

If this is about the return value, it is not stored in errno.

Indeed. It's stored in exit_code within the process task_struct, along with other useful data about the terminated process and is the reason that process descriptors remain around.

When you call wait4 or one of the wait functions, then this gets cleaned up.

Cheers,

Jon.