What is the difference between exit(0) and exit(1) in C?

前端 未结 11 1800
时光取名叫无心
时光取名叫无心 2020-12-22 17:19

Can anyone tell me? What is the difference between exit(0) and exit(1) in C language?

相关标签:
11条回答
  • 2020-12-22 18:20

    When the executable ends (exits) it returns a value to the shell that ran it. exit(0) usually indicates that all is well, whilst exit(1) indicates that something has gone amiss.

    0 讨论(0)
  • 2020-12-22 18:20

    exit(0) means Program(Process) terminate normally successfully..

    exit(1) means program(process) terminate normally unsuccessfully..

    If you want to observe this thing you must know signal handling and process management in Unix ...

    know about sigaction, watipid()..for()...such....API...........

    0 讨论(0)
  • 2020-12-22 18:21

    exit() should always be called with an integer value and non-zero values are used as error codes.

    See also: Use of exit() function

    0 讨论(0)
  • 2020-12-22 18:22

    exit(0) behave like return 0 in main() function, exit(1) behave like return 1. The standard is, that main function return 0, if program ended successfully while non-zero value means that program was terminated with some kind of error.

    0 讨论(0)
  • 2020-12-22 18:22

    exit(0) is equivalent to exit(EXIT_SUCCESS).

    exit(1) is equivalent to exit(EXIT_FAILURE).

    On failure normally any positive value get returned to exit the process, that you can find on shell by using $?.

    Value more than 128 that is caused the termination by signal. So if any shell command terminated by signal the return status must be (128+signal number).

    For example:

    If any shell command is terminated by SIGINT then $? will give 130 ( 128+2) (Here 2 is signal number for SIGINT, check by using kill -l )

    0 讨论(0)
提交回复
热议问题