linux中出错处理

2023-05-16

linux中,在支持多线程的环境中,通常每个线程都有属于自己的errno变量,是用来表示特定错误的常量。

 

以下是<errno.h>中定义的所有出错errno常量

 

#define EPERM            1      /* Operation not permitted */
#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      /* Argument list too long */
#define ENOEXEC          8      /* Exec format error */
#define EBADF            9      /* Bad file number */
#define ECHILD          10      /* No child processes */
#define EAGAIN          11      /* Try again */
#define ENOMEM          12      /* Out of memory */
#define EACCES          13      /* Permission denied */
#define EFAULT          14      /* Bad address */
#define ENOTBLK         15      /* Block device required */
#define EBUSY           16      /* Device or resource busy */
#define EEXIST          17      /* File exists */
#define EXDEV           18      /* Cross-device link */
#define ENODEV          19      /* No such device */
#define ENOTDIR         20      /* Not a directory */
#define EISDIR          21      /* Is a directory */
#define EINVAL          22      /* Invalid argument */
#define ENFILE          23      /* File table overflow */
#define EMFILE          24      /* Too many open files */
#define ENOTTY          25      /* Not a typewriter */
#define ETXTBSY         26      /* Text file busy */
#define EFBIG           27      /* File too large */
#define ENOSPC          28      /* No space left on device */
#define ESPIPE          29      /* Illegal seek */
#define EROFS           30      /* Read-only file system */
#define EMLINK          31      /* Too many links */
#define EPIPE           32      /* Broken pipe */
#define EDOM            33      /* Math argument out of domain of func */
#define ERANGE          34      /* Math result not representable */
#define EDEADLK         35      /* Resource deadlock would occur */
#define ENAMETOOLONG    36      /* File name too long */
#define ENOLCK          37      /* No record locks available */
#define ENOSYS          38      /* Function not implemented */
#define ENOTEMPTY       39      /* Directory not empty */
#define ELOOP           40      /* Too many symbolic links encountered */
#define EWOULDBLOCK     EAGAIN  /* Operation would block */
#define ENOMSG          42      /* No message of desired type */
#define EIDRM           43      /* Identifier removed */
#define ECHRNG          44      /* Channel number out of range */
#define EL2NSYNC        45      /* Level 2 not synchronized */
#define EL3HLT          46      /* Level 3 halted */
#define EL3RST          47      /* Level 3 reset */
#define ELNRNG          48      /* Link number out of range */
#define EUNATCH         49      /* Protocol driver not attached */
#define ENOCSI          50      /* No CSI structure available */
#define EL2HLT          51      /* Level 2 halted */
#define EBADE           52      /* Invalid exchange */
#define EBADR           53      /* Invalid request descriptor */
#define EXFULL          54      /* Exchange full */
#define ENOANO          55      /* No anode */
#define EBADRQC         56      /* Invalid request code */
#define EBADSLT         57      /* Invalid slot */
#define EDEADLOCK       EDEADLK  58
#define EBFONT          59      /* Bad font file format */
#define ENOSTR          60      /* Device not a stream */
#define ENODATA         61      /* No data available */
#define ETIME           62      /* Timer expired */
#define ENOSR           63      /* Out of streams resources */
#define ENONET          64      /* Machine is not on the network */
#define ENOPKG          65      /* Package not installed */
#define EREMOTE         66      /* Object is remote */
#define ENOLINK         67      /* Link has been severed */
#define EADV            68      /* Advertise error */
#define ESRMNT          69      /* Srmount error */
#define ECOMM           70      /* Communication error on send */
#define EPROTO          71      /* Protocol error */
#define EMULTIHOP       72      /* Multihop attempted */
#define EDOTDOT         73      /* RFS specific error */
#define EBADMSG         74      /* Not a data message */
#define EOVERFLOW       75      /* Value too large for defined data type */
#define ENOTUNIQ        76      /* Name not unique on network */
#define EBADFD          77      /* File descriptor in bad state */
#define EREMCHG         78      /* Remote address changed */
#define ELIBACC         79      /* Can not access a needed shared library */
#define ELIBBAD         80      /* Accessing a corrupted shared library */
#define ELIBSCN         81      /* .lib section in a.out corrupted */
#define ELIBMAX         82      /* Attempting to link in too many shared libraries */
#define ELIBEXEC        83      /* Cannot exec a shared library directly */
#define EILSEQ          84      /* Illegal byte sequence */
#define ERESTART        85      /* Interrupted system call should be restarted */
#define ESTRPIPE        86      /* Streams pipe error */
#define EUSERS          87      /* Too many users */
#define ENOTSOCK        88      /* Socket operation on non-socket */
#define EDESTADDRREQ    89      /* Destination address required */
#define EMSGSIZE        90      /* Message too long */
#define EPROTOTYPE      91      /* Protocol wrong type for socket */
#define ENOPROTOOPT     92      /* Protocol not available */
#define EPROTONOSUPPORT 93      /* Protocol not supported */
#define ESOCKTNOSUPPORT 94      /* Socket type not supported */
#define EOPNOTSUPP      95      /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT    96      /* Protocol family not supported */
#define EAFNOSUPPORT    97      /* Address family not supported by protocol */
#define EADDRINUSE      98      /* Address already in use */
#define EADDRNOTAVAIL   99      /* Cannot assign requested address */
#define ENETDOWN        100     /* Network is down */
#define ENETUNREACH     101     /* Network is unreachable */
#define ENETRESET       102     /* Network dropped connection because of reset */
#define ECONNABORTED    103     /* Software caused connection abort */
#define ECONNRESET      104     /* Connection reset by peer */
#define ENOBUFS         105     /* No buffer space available */
#define EISCONN         106     /* Transport endpoint is already connected */
#define ENOTCONN        107     /* Transport endpoint is not connected */
#define ESHUTDOWN       108     /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS    109     /* Too many references: cannot splice */
#define ETIMEDOUT       110     /* Connection timed out */
#define ECONNREFUSED    111     /* Connection refused */
#define EHOSTDOWN       112     /* Host is down */
#define EHOSTUNREACH    113     /* No route to host */
#define EALREADY        114     /* Operation already in progress */
#define EINPROGRESS     115     /* Operation now in progress */
#define ESTALE          116     /* Stale NFS file handle */
#define EUCLEAN         117     /* Structure needs cleaning */
#define ENOTNAM         118     /* Not a XENIX named type file */
#define ENAVAIL         119     /* No XENIX semaphores available */
#define EISNAM          120     /* Is a named type file */
#define EREMOTEIO       121     /* Remote I/O error */
#define EDQUOT          122     /* Quota exceeded */
#define ENOMEDIUM       123     /* No medium found */
#define EMEDIUMTYPE     124     /* Wrong medium type */
#define ECANCELED       125     /* Operation Canceled */
#define ENOKEY          126     /* Required key not available */
#define EKEYEXPIRED     127     /* Key has expired */
#define EKEYREVOKED     128     /* Key has been revoked */
#define EKEYREJECTED    129     /* Key was rejected by service */
/* for robust mutexes */
#define EOWNERDEAD      130     /* Owner died */
#define ENOTRECOVERABLE 131     /* State not recoverable */

 

 

对于errno的应用,应该知道两条规则:

第一,如果没有出错,则其值不会被一个例程清除。也即是如果没有出错,errno的值将不会被修改。

第二,任意一个函数都不会将errno值设置为0。

 

C标准定义了两个函数,帮助打印出错信息。

 

此函数映射为出错消息字符串,并返回该字符串指针。

 

此函数的一般用法如下:

 

fprintf(stderr, " EACCS:%s/n", strerror(EACCES));  //其中,stderr标准出错文件描述符,就是将信息显示在屏幕上

 

 

它首先输出由msg指向的字符串,然后是一个冒号,一个空格,接着是对应于errno值的出错消息,最后是一个换行符。

 

一般情况下是strerror和perror连用。

如果只使用perror函数,那么它会自动在出错消息字符串之后显示errno值的出错信息

 

格式如下  string:  errno的字符串/n

这样有可能是打印上一次的错误信息。所以,在使用perror函数之前要确保errno被赋值到特定的错误编号。

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

linux中出错处理 的相关文章

  • docker容器大小远大于实际大小

    我正在尝试从中构建图像debian latest 构建后 报告的图像虚拟大小来自docker images命令为 1 917 GB 我登录查看尺寸 du sh 大小为 573 MB 我很确定这么大的尺寸通常是不可能的 这里发生了什么 如何获
  • 我的线程图像生成应用程序如何将其数据传输到 GUI?

    Mandelbrot 生成器的缓慢多精度实现 线程化 使用 POSIX 线程 Gtk 图形用户界面 我有点失落了 这是我第一次尝试编写线程程序 我实际上并没有尝试转换它的单线程版本 只是尝试实现基本框架 到目前为止它是如何工作的简要描述 M
  • ftrace:仅打印trace_printk()的输出

    是否可以只转储trace printk 输出于trace文件 我的意思是过滤掉函数跟踪器 或任何其他跟踪器 中的所有函数 一般来说 您可以在选项目录中关闭选项 sys kernel debug tracing options Use ls显
  • 如何确保应用程序在 Linux 上持续运行

    我试图确保脚本在开发服务器上保持运行 它会整理统计数据并提供网络服务 因此它应该会持续存在 但一天中有几次 它会因未知原因而消失 当我们注意到时 我们只需再次启动它 但这很麻烦 并且某些用户没有权限 或专有技术 来启动它 作为一名程序员 我
  • Linux 上有关 getBounds() 和 setBounds() 的 bug_id=4806603 的解决方法?

    在 Linux 平台上 Frame getBounds 和 Frame setBounds 的工作方式不一致 这在 2003 年就已经有报道了 请参见此处 http bugs java com bugdatabase view bug do
  • 按进程名称过滤并记录 CPU 使用情况

    Linux 下有选项吗顶部命令 https www man7 org linux man pages man1 top 1 html我可以在哪里按名称过滤进程并将每秒该进程的 CPU 使用情况写入日志文件 top pgrep 过滤输出top
  • 如何在基于 Linux 的系统上的 C 程序中使用 mqueue?

    如何在基于 Linux 的系统上的 C 程序中使用 mqueue 消息队列 我正在寻找一些好的代码示例 可以展示如何以正确且正确的方式完成此操作 也许是一个操作指南 下面是一个服务器的简单示例 该服务器接收来自客户端的消息 直到收到告诉其停
  • 如何减去两个 gettimeofday 实例?

    我想减去两个 gettimeofday 实例 并以毫秒为单位给出答案 这个想法是 static struct timeval tv gettimeofday tv NULL static struct timeval tv2 gettime
  • 确定我可以向文件句柄写入多少内容;将数据从一个 FH 复制到另一个 FH

    如何确定是否可以将给定数量的字节写入文件句柄 实际上是套接字 或者 如何 取消读取 我从其他文件句柄读取的数据 我想要类似的东西 n how much can I write w handle n read r handle buf n a
  • Windows CE 与嵌入式 Linux [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 现在我确信我们都清楚 Linux 与 Windows 桌面的相对优点 然而 我对嵌入式开发世界的了解却少得多 我主要对行业解决方案感兴
  • 在 Mac OSX 上交叉编译 x86_64-unknown-linux-gnu 失败

    我尝试将我的 Rust 项目之一编译到 x86 64 unknown linux gnu 目标 cargo build target x86 64 unknown linux gnu Compiling deployer v0 1 0 fi
  • git 错误:无法处理 https

    当我尝试使用 git clone 时https xxx https xxx我收到以下错误我不处理协议 https 有人可以帮我吗 完整消息 dementrock dementrock A8Se git 克隆https git innosta
  • Mcrt1.o和Scrt1.o有什么用?

    我坚持使用以下两个文件 即 Mcrt1 o 和 Scrt1 o 谁能帮我知道这两个文件的用途 如何使用它 我们以 gcrt1 o 为例 在使用 pg 选项编译进行性能测试时非常有用 谢谢 表格的文件 crt o总是 C 运行时启动代码 大部
  • 从 systemd bash 内联脚本创建 filename_$(date %Y-%m-%d)

    我正在尝试执行systemd计时器并希望将执行脚本的输出保存在每个日期的文件中 这是我的ExecStart脚本中的 service file ExecStart bin bash c echo date Y m d gt gt home u
  • 后台分叉无法正常工作[重复]

    这个问题在这里已经有答案了 我运行这个程序 在前景和背景中 int main int pid printf App Start pid d n getpid while 1 pid fork if pid 0 printf Child n
  • 如何从 PROC 获取有关子进程的信息

    我正在尝试编写一个以几个进程作为参数的程序 然后父进程执行每个子进程并打印出一些相关的统计信息 示例 generate ls l 将生成一个程序 打印出有关 ls l 的一些统计信息 特别是其系统时间 用户时间和上下文切换次数 我不想使用
  • Gearman,php 扩展问题:使用终端在 .. 中找不到类“GearmanWorker”,但可以在浏览器上使用

    我最近在 ubuntu 10 04 上安装了 gearman 并安装了它的 pecl 扩展 现在 当我在浏览器中运行一个 php 文件时 其中包含 client new GearmanWorker die var Dump client I
  • vagrant ssh -c 并在连接关闭后保持后台进程运行

    我正在编写一个脚本来启动和后台流浪机器内的进程 似乎每次脚本结束和 ssh 会话结束时 后台进程也会结束 这是我正在运行的命令 vagrant ssh c cd vagrant src nohup python hello py gt he
  • C:如果文件描述符被删除,阻塞读取应该返回

    我正在以阻塞的方式从设备 文件描述符中读取 可能会发生这样的情况 在不同的线程中 设备被关闭并且文件描述符被删除 不幸的是 读取没有返回或注意到并且一直阻塞 作为一种解决方法 我可以使用 select 作为超时来执行 while 循环 如果
  • X11 模式对话框

    如何使用 Xlib 在 X11 中创建模式对话框 模态对话框是一个位于应用程序其他窗口之上的窗口 就像瞬态窗口一样 并且拒绝将焦点给予应用程序的其他窗口 在 Windows 中 当试图从模态窗口夺取焦点时 模态也会通过闪 烁模态窗口的标题栏

随机推荐

  • 可解压rar、zip且可打包7z的powershell命令

    安装模块 Install Module 7zip4powershell 为什么要使用7zip 1个原因是传统zip只支持最大2gb的文件 xff0c 而7zip支持 16 xff0c 000 xff0c 000TB大的文档 xff0c 另一
  • ubuntu18.04 systemd配置学习手册(1) --相关概念

    1 从init系统说起 Linux 操作系统的启动首先从 BIOS 开始 xff0c 接下来进入 boot loader xff0c 由 bootloader 载入内核 xff0c 进行内核初始化 内核初始化的最后一步就是启动 PID 为
  • ubuntu18.04 systemd配置学习手册(2) --具体使用

    转载 xff1a http www ruanyifeng com blog 2016 03 systemd tutorial part two html 1 开机启动 对于那些支持 Systemd 的软件 xff0c 安装的时候 xff0c
  • 建造者模式(Builder模式)详解

    在软件开发过程中有时需要创建一个复杂的对象 xff0c 这个复杂对象通常由多个子部件按一定的步骤组合而成 例如 xff0c 计算机是由 OPU 主板 内存 硬盘 显卡 机箱 显示器 键盘 鼠标等部件组装而成的 xff0c 采购员不可能自己去
  • 关于读取文件失败

    太久没遇上这个问题了 今天碰上刚好回顾一下 文件路径以及python语法中涉及到的反斜杠 转义符问题 xff0c 在python字符串中 有转义的含义 xff0c 如 t可代表TAB xff0c n代表换行 xff0c 所以我们需要采取一些
  • GKI改造原则、机制和方法

    Google在android11 5 4分支上开始要求所有下游厂商使用Generic Kernel Image xff08 GKI xff09 xff0c 需要将SoC和device相关的代码从核心内核剥离到可加载模块中 xff08 下文称
  • Blazor入门100天 : 身份验证和授权 (1) - 建立带身份验证工程

    目录 建立默认带身份验证 Blazor 程序角色 组件 特性 过程逻辑DB 改 Sqlite将自定义字段添加到用户表脚手架拉取IDS文件 本地化资源freesql 生成实体类 freesql 管理ids数据表初始化 Roles freesq
  • 黑屏定屏那些事 - 系统机制,分析套路和实战(系统篇)

    本文发表于内核工匠公众号 xff0c 旨在给内核开发的小伙伴分享 xff1a Android系统层面用户UI交互的设计 xff0c 从而理解手机黑屏定屏时背后的故事 Android系统对黑屏定屏类问题的维测思路 xff0c 有那些先进的思想
  • ArrayList和JSONArray边遍历边删除到底该怎么做

    话题看起来有点老生了 xff0c 但是加入JSONArray还是有很多新意 ArrayList 方式1 xff1a 索引遍历 List lt Integer gt list 61 new ArrayList lt gt list add 1
  • git 添加源地址和查看源地址

    git init 添加本地文件关联 git add commit 提交 git commit m 34 first commit 34 关联仓库 git remote add origin http git sfc com yuxang w
  • Python爬取淘宝商品数据,价值千元的爬虫外包项目

    前言 本文的文字及图片来源于网络 仅供学习 交流使用 不具有任何商业用途 如有问题请及时联系我们以作处理 PS xff1a 如有需要Python学习资料的小伙伴可以加点击下方链接自行获取 完整代码可以点击下方链接获取 python免费学习资
  • AndroidStudio安装kotlin插件

    转载请注明出处 xff1a http blog csdn net feibendexiaoma article details 72625846 前言 2017 Google I O大会宣布将Kotlin语言作为安卓开发的一级编程语言 xf
  • Ubuntu20.04/Ubuntu22.04 配置VScode+Opencv+cmake(C++)

    Ubuntu20 04 Ubuntu22 04 配置VScode 43 Opencv 43 cmake xff08 C 43 43 xff09 下面介绍Ubuntu20 04下安装opencv xff0c 当然Ubuntu22 04也适用
  • Ubuntu-解决包依赖关系

    Ubuntu 解决包依赖关系的办法 安装软件包的时候 xff0c 有时会遇到类似下图的依赖问题 xff0c 无法正常安装 xff0c 下面提供三种方法解决依赖问题 1 可以尝试用下面方法处理依赖问题 xff0c 紧跟前一条安装命令后面输入下
  • Ubuntu 18.04系统进不去了,只有老内核的恢复模式还能进,请大家帮看一下

    Ubuntu 18 04 新内核和恢复模式进不去 xff0c 会报错 老内核也进不去 xff0c 只有老内核的恢复模式能进 xff0c 请大佬帮看一下 virtualbox里安装的是Ubuntu 18 04 1 LTS xff0c 打开id
  • Android Lottie动画的简单使用

    简介 在Android中做动画效果无非是以下几种方法 xff1a 普通动画帧动画属性动画通过改变LayoutParams布局参数来实现动画 现如今在Github上有一个比较火的动画库Lottie xff0c Github上关于Lottie库
  • java运行提示没有 org/slf4j/LoggerFactory 或者 log4j

    问题描述 Exception in thread main java lang NoClassDefFoundError org slf4j LoggerFactory 解决办法 在pom xml里面添加对应的配置 将jar包大包进去 lt
  • Blazor入门100天 : 身份验证和授权 (3) - DB改Sqlite

    目录 建立默认带身份验证 Blazor 程序角色 组件 特性 过程逻辑DB 改 Sqlite将自定义字段添加到用户表脚手架拉取IDS文件 本地化资源freesql 生成实体类 freesql 管理ids数据表初始化 Roles freesq
  • ExecutorService等待线程完成后优雅结束

    1 概述 该ExecutorService框架可以很容易地在处理多线程任务 我们将举例说明我们等待线程完成执行的一些场景 此外 xff0c 我们将展示如何正常关闭ExecutorService并等待已经运行的线程完成其执行 2 Execut
  • linux中出错处理

    linux中 xff0c 在支持多线程的环境中 xff0c 通常每个线程都有属于自己的errno变量 xff0c 是用来表示特定错误的常量 以下是 lt errno h gt 中定义的所有出错errno常量 define EPERM 1 O