C언어 main함수에서 return 0; 이유 및 의미

ChaeMin Lyu·2023년 4월 16일
2
int main()
{
	...
    return 0;
}


(http://cis2.oc.ctc.edu/oc_apps/Westlund/xbook/xbook.php?unit=04&proc=page&numb=1)


(https://devwhkang.gatsbyjs.io/posts/os-systemcall/)

$ ./a.out
$ echo $?
0

만약 main함수에서 return 1을 한다면, echo $?에서 1이 출력된다.

https://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables

  • $1, $2, $3, ... are the positional parameters.
  • "$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}.
  • "$*" is the IFS expansion of all positional parameters, $1 - $2 $3 ....
  • $# is the number of positional parameters.
  • $- current options set for the shell.
  • $$ pid of the current shell (not subshell).
  • $_ most recent parameter (or the abs path of the command to start the current shell immediately after startup).
  • $IFS is the (input) field separator.
  • $? is the most recent foreground pipeline exit status.
  • $! is the PID of the most recent background command.
  • $0 is the name of the shell or shell script.

linux에서 SUCEESS는 0으로 정의한다.
(https://m.blog.naver.com/geartec82/220863754963)

https://android.googlesource.com/kernel/lk/+/dima/for-travis/include/errno.h

#define	EPERM 1		/* Not super-user */
#define	ENOENT 2	/* No such file or directory */
#define	ESRCH 3		/* No such process */
#define	EINTR 4		/* Interrupted system call */
#define	EIO 5		/* I/O error */
#define	ENXIO 6		/* No such device or address */
#define	E2BIG 7		/* Arg list too long */
#define	ENOEXEC 8	/* Exec format error */
#define	EBADF 9		/* Bad file number */
#define	ECHILD 10	/* No children */
#define	EAGAIN 11	/* No more processes */
...
profile
유부초밥을 좋아하는 채민류

0개의 댓글