什么是Linux中/ bash程序返回值的有效范围? [英] What is the valid range for program return value in Linux/bash?

查看:506
本文介绍了什么是Linux中/ bash程序返回值的有效范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C程序返回一个整数值。我很惊讶地发现,从shell提示符检查返回值时,我得到的数值模256。

  / * * prog.c中/
INT主(...){返回257; }

-

 > ./prog.e
>回声$?
1


  • 为什么我不能看到整个整数?

  • 哪里是这种行为记录?

  • 我怎样才能得到整个32位值到shell?


解决方案

  

当程序退出时,它可以返回到父进程的少量信息,有关终止的原因,使用退出状态。这是介于0和255之间的值,该退出的过程传递作为参数退出。


<一个href=\"http://www.gnu.org/s/hello/manual/libc/Exit-Status.html\">http://www.gnu.org/s/hello/manual/libc/Exit-Status.html

或者

http://en.wikipedia.org/wiki/Exit_status

从POSIX回报codeS

来了,C返回codeS各自的谷歌搜索。

I have a C program which returns an integer value. I was surprised to find out that when examining the return value from the shell prompt I get the value modulo 256.

/* prog.c */
int main(...) { return 257; }

--

> ./prog.e
> echo $?  
1

  • Why don't I see the whole integer?
  • Where is this behavior documented?
  • How can I get the whole 32-bit value to the shell?

解决方案

When a program exits, it can return to the parent process a small amount of information about the cause of termination, using the exit status. This is a value between 0 and 255 that the exiting process passes as an argument to exit.

http://www.gnu.org/s/hello/manual/libc/Exit-Status.html

alternatively:

http://en.wikipedia.org/wiki/Exit_status

came from "posix return codes" and "c return codes" respective Google searches.

这篇关于什么是Linux中/ bash程序返回值的有效范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆