* exit(42)
@ 2004-09-24 11:57 Ankit Jain
2004-09-24 12:13 ` exit(42) Alphex Kaanoken
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Ankit Jain @ 2004-09-24 11:57 UTC (permalink / raw)
To: linux prg
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-24 11:57 exit(42) Ankit Jain
@ 2004-09-24 12:13 ` Alphex Kaanoken
2004-09-24 12:25 ` exit(42) Ron Michael Khu
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Alphex Kaanoken @ 2004-09-24 12:13 UTC (permalink / raw)
To: Ankit Jain; +Cc: linux-c-programming
On Fri, 24 Sep 2004 12:57:59 +0100 (BST)
Ankit Jain <ankitjain1580@yahoo.com> wrote:
> well do any body know what does this mean?
>
> exit(42)
It mean - "No message of desired type",
>
> 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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Alphex Kaanoken,
Senior Developer of
Crew IT research labs.
Web: http://crew.org.ru
Mail: kaanoken at crew.org.ru
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-24 11:57 exit(42) Ankit Jain
2004-09-24 12:13 ` exit(42) Alphex Kaanoken
@ 2004-09-24 12:25 ` Ron Michael Khu
2004-09-27 9:16 ` exit(42) Pankaj
2004-09-24 12:29 ` exit(42) Luciano Moreira - igLnx
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Ron Michael Khu @ 2004-09-24 12:25 UTC (permalink / raw)
To: Ankit Jain; +Cc: linux prg
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...
Ankit Jain wrote:
>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 majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-24 11:57 exit(42) Ankit Jain
2004-09-24 12:13 ` exit(42) Alphex Kaanoken
2004-09-24 12:25 ` exit(42) Ron Michael Khu
@ 2004-09-24 12:29 ` Luciano Moreira - igLnx
2004-09-24 16:33 ` exit(42) Jan-Benedict Glaw
2004-09-25 1:13 ` exit(42) Micha Feigin
4 siblings, 0 replies; 10+ messages in thread
From: Luciano Moreira - igLnx @ 2004-09-24 12:29 UTC (permalink / raw)
To: Ankit Jain; +Cc: linux prg
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
Ankit Jain wrote:
>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 majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-24 11:57 exit(42) Ankit Jain
` (2 preceding siblings ...)
2004-09-24 12:29 ` exit(42) Luciano Moreira - igLnx
@ 2004-09-24 16:33 ` Jan-Benedict Glaw
2004-09-25 1:13 ` exit(42) Micha Feigin
4 siblings, 0 replies; 10+ messages in thread
From: Jan-Benedict Glaw @ 2004-09-24 16:33 UTC (permalink / raw)
To: linux prg
[-- Attachment #1: Type: text/plain, Size: 1439 bytes --]
On Fri, 2004-09-24 12:57:59 +0100, Ankit Jain <ankitjain1580@yahoo.com>
wrote in message <20040924115759.6133.qmail@web52908.mail.yahoo.com>:
> well do any body know what does this mean?
>
> exit(42)
It just leaves 42 (Illuminati!) back to the caller.
> 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."
> 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.
> 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
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +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));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-24 11:57 exit(42) Ankit Jain
` (3 preceding siblings ...)
2004-09-24 16:33 ` exit(42) Jan-Benedict Glaw
@ 2004-09-25 1:13 ` Micha Feigin
2004-09-25 10:57 ` exit(42) rinku rathore
4 siblings, 1 reply; 10+ messages in thread
From: Micha Feigin @ 2004-09-25 1:13 UTC (permalink / raw)
To: linux prg
On Fri, Sep 24, 2004 at 12:57:59PM +0100, Ankit Jain wrote:
> 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.
> 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.
> 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).
> 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 majordomo@vger.kernel.org
> 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.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-25 1:13 ` exit(42) Micha Feigin
@ 2004-09-25 10:57 ` rinku rathore
0 siblings, 0 replies; 10+ messages in thread
From: rinku rathore @ 2004-09-25 10:57 UTC (permalink / raw)
To: Micha Feigin; +Cc: linux-c-programming
--- Micha Feigin <michf@post.tau.ac.il> wrote:
> On Fri, Sep 24, 2004 at 12:57:59PM +0100, Ankit Jain
> wrote:
> > 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.
>
> > 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.
>
> > 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).
>
> > 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 majordomo@vger.kernel.org
> > 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.
> >
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-24 12:25 ` exit(42) Ron Michael Khu
@ 2004-09-27 9:16 ` Pankaj
2004-09-27 12:39 ` exit(42) Micha Feigin
0 siblings, 1 reply; 10+ messages in thread
From: Pankaj @ 2004-09-27 9:16 UTC (permalink / raw)
To: Ron Michael Khu; +Cc: Ankit Jain, linux prg
hi,
I guess the value is stored in a global var called "errno".
Pankaj
On Friday 24 Sep 2004 5:55 pm, Ron Michael Khu wrote:
> > linux-c-programming" in the body of a message to
> > majordomo@vger.kernel.org
> >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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Only one man in a thousand is a leader of men
Remaining 999 follow women.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-27 9:16 ` exit(42) Pankaj
@ 2004-09-27 12:39 ` Micha Feigin
2004-09-27 13:54 ` exit(42) Jon Masters
0 siblings, 1 reply; 10+ messages in thread
From: Micha Feigin @ 2004-09-27 12:39 UTC (permalink / raw)
To: linux prg
On Mon, Sep 27, 2004 at 02:46:03PM +0530, Pankaj wrote:
> 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).
> Pankaj
> On Friday 24 Sep 2004 5:55 pm, Ron Michael Khu wrote:
> > > linux-c-programming" in the body of a message to
> > > majordomo@vger.kernel.org
> > >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 majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> --
> 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 majordomo@vger.kernel.org
> 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.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: exit(42)
2004-09-27 12:39 ` exit(42) Micha Feigin
@ 2004-09-27 13:54 ` Jon Masters
0 siblings, 0 replies; 10+ messages in thread
From: Jon Masters @ 2004-09-27 13:54 UTC (permalink / raw)
To: linux prg
On Mon, 27 Sep 2004 14:39:55 +0200, Micha Feigin <michf@post.tau.ac.il> wrote:
> On Mon, Sep 27, 2004 at 02:46:03PM +0530, Pankaj wrote:
> > 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-09-27 13:54 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-24 11:57 exit(42) Ankit Jain
2004-09-24 12:13 ` exit(42) Alphex Kaanoken
2004-09-24 12:25 ` exit(42) Ron Michael Khu
2004-09-27 9:16 ` exit(42) Pankaj
2004-09-27 12:39 ` exit(42) Micha Feigin
2004-09-27 13:54 ` exit(42) Jon Masters
2004-09-24 12:29 ` exit(42) Luciano Moreira - igLnx
2004-09-24 16:33 ` exit(42) Jan-Benedict Glaw
2004-09-25 1:13 ` exit(42) Micha Feigin
2004-09-25 10:57 ` exit(42) rinku rathore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).