返回 1 与返回 0(用户和程序员) [英] return 1 vs return 0 (user and programmer)
问题描述
我之前看过一些关于返回 1 和返回 0 的帖子,以下是我的理解:
I've seen some previous posts on return 1 and return 0, and here is what I understand:
对于程序的用户(不会看源代码的人)来说,return 1 和 return 0 没有区别.
For the user (someone who won't look at the source code) of the program, there is no distinction between return 1 and return 0.
对于程序员来说,return 1 表示错误,return 0 表示正常执行.
For the programmer, return 1 implies error, and return 0 implies normal execution.
我理解正确吗?
抱歉,我认为这无关紧要,但我是在 main() 的上下文中讨论的.
Hi, sorry, I didn't think this mattered, but I am talking about in the context of main().
推荐答案
程序的退出状态可以是whatever给定程序希望它是[mean].
The exit status of a program can be whatever a given program wants it to be [mean].
虽然大多数程序通过:0=success, 1=error
,但其他一些程序做不同的事情.
While most programs get by with: 0=success, 1=error
, some others do different things.
来自 POSIX/Unix/Linux 的一些示例:
Some examples from POSIX/Unix/Linux:
true
程序总是以 0 退出.false
程序总是以 1 退出.那么,[学术上] false
失败了吗?
The true
program always exits with 0. The false
program always exits with 1. So, [academically speaking] did false
fail?
cmp
和 diff
程序做了:0=文件匹配,1=文件不同,2=其他
[2
通常意味着被比较的文件之一不存在].
The cmp
and diff
programs do: 0=files match, 1=files differ, 2=other
[2
usually means one of the files being compared does not exist].
rsync
程序有许多 退出代码:0=success, non-zero=error
.但是,rsync
失败的原因有很多.因为 rsync
在实时 FS 上工作,所以可以重试一些错误.例如,源上的文件在 rsync
发生时被删除(代码 23
或 24
).这可以重试.对于一些超时错误也是如此.
The rsync
program has many exit codes: 0=success, non-zero=error
. But, there are many ways rsync
can fail. Because rsync
works on a live FS, some errors can be retried. For example, a file on the source is removed while the rsync
is happening (code 23
or 24
). This can be retried. Likewise for some timeout errors.
EXIT VALUES
0 Success
1 Syntax or usage error
2 Protocol incompatibility
3 Errors selecting input/output files, dirs
4 Requested action not supported: an attempt was made to manipu‐
late 64-bit files on a platform that cannot support them; or an
option was specified that is supported by the client and not by
the server.
5 Error starting client-server protocol
6 Daemon unable to append to log-file
10 Error in socket I/O
11 Error in file I/O
12 Error in rsync protocol data stream
13 Errors with program diagnostics
14 Error in IPC code
20 Received SIGUSR1 or SIGINT
21 Some error returned by waitpid()
22 Error allocating core memory buffers
23 Partial transfer due to error
24 Partial transfer due to vanished source files
25 The --max-delete limit stopped deletions
30 Timeout in data send/receive
35 Timeout waiting for daemon connection
这篇关于返回 1 与返回 0(用户和程序员)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!