exit function doubts

At many places in program I see exit() being called with 2 passed as parameter to it.

exit(2);

What does this 2 stands for?
Can I get a list all such parameters to exit?

This is just a exit status code that script returns to what ever called it, most of the time it it is non-zero that means it is trying to tell the caller there was some type of error or exception condition that occurred.

1 Like

Zero means success, anything else means some sort of error, but the exact meanings are specific to the program.

1 Like

Some applications and UNIX code follow the sysexits protocol

For example see:
sysexits(3) - preferable exit codes for programs

1 Like

Hello,

I want to know what is the meaning of code
exit(3);

You have to ask the person who wrote the code. Lots of things simply return what appears to us as an arbitrary non-zero number on error. The man page usually indicates what the return codes mean -- if this error came from a command that is documented on your system.

A direct answer: nobody, by themselves, can know for sure without a lot of research. Either reading the original code or asking the coder is the best way to know. Sometimes a manpage can help.

You could run

grep progname *

in any directory containing scripts that are written, where progname = the script that gives that exit. The program that called it will use the

$? 

construct, if it is for a Bourne script, to decide what to do if the exit code = 3.