errno

Default value of errno variable [closed]

为君一笑 提交于 2019-12-07 16:47:34
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I want to use the errno library in order to define the return of a project (c language) functions. And I'm wondering about something... I will do something like this : #include <errno.h> int myfunction (void) { int res; /*Some actions....*/ if(success) res = 0; else if (fail)

Linux, convert errno to name

夙愿已清 提交于 2019-12-07 04:48:24
问题 I am looking for an API to convert an errno integer to its name. For example: int fd; if((fd = open(path, O_RDONLY)) == -1) printf("error: %d %s %s\n", errno, strerror(errno), ERRNONAME(errno)); So, ERRNONAME would yield a name, such as "EINVAL" , "EPERM" , etc. Is this possible? 回答1: I recently wrote the errnoname library that has an errnoname function which does exactly this. There is unfortunately still no standard API to do this in C, and near as I can tell no other open source C library

Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe?

青春壹個敷衍的年華 提交于 2019-12-07 01:29:11
问题 Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe? If no, is it the case for all versions of gcc / linux / solaris or is it required for certain old versions? I recently tested a piece of code where _REENTRANT was not used and found the errno behaving in an undefined fahsion in multi thread environment? But, after adding _REENTRANT everything was working fine. The Environment was Solaris. But, the discussion here doesn't seem to say it is

linux上的进程通信学习笔记

大城市里の小女人 提交于 2019-12-07 00:17:42
参考资料 <<精通Linux C编程>> http://man7.org/linux/man-pages/man2/open.2.html https://www.cnblogs.com/52php/p/5840229.html 在 Android中的Handler的Native层研究 文章中研究一下一把Linux中的匿名管道的通信机制,今天这里Linux中的进程间通信补齐。 在Linux中,实现进程通信的方法包括管道(匿名管道和具名管道),消息队列,信号量,共享内存,套接口等。消息队列,信号量,共享内存统称为系统的(POSIX和System V)IPC,用于本地间的进程通信,套接口(socket)则运用于远程进程通信。 各个通信机制定义如下: 匿名管道(Pipe)和具名管道(named pipe):匿名管道用于具有亲缘关系进程间的通信,具名管道克服了管道没有名字的限制,因此除了具有匿名管道的功能外,还允许在无亲缘关系的进程中进行通信。 消息队列(Message):消息队列为消息的链接表,包括POSIX消息队列和System V消息队列。有足够权限的进程可以向队列中添加消息,被赋予读权限的进程则可以读取队列中的消息。 共享内存:是的多个进程可以访问同一块内存空间,是最快的可以IPC形式。是针对其他的通信机制运行效率较低而设计出来的。往往与其他通信机制,如信号量结合使用

2019-2020-1 20175301 20175305 20175318 实验五 通讯协议设计

℡╲_俬逩灬. 提交于 2019-12-06 22:11:29
2019-2020-1 20175301 20175305 20175318 实验五 通讯协议设计 实验内容 任务一 在Ubuntu中完成作业 openSSL OpenSSL是一个SSL协议的开源实现,采用C语言作为开发语言,具备了跨平台的能力,支持Unix/Linux、Windows、Mac OS等多种平台。 三个主要功能部分: 密码算法库:OpenSSL的基础部分,也是很值得一般密码安全技术人员研究的部分。实现了目前大部分主流的密码算法和标准。 SSL协议库:在密码算法库的基础上实现的,SSL协议部分完全实现和封装了SSL协议的三个版本和TLS协议。 应用程序:覆盖了密码技术的应用,主要包括了各种算法的加密程序和各种类型密钥的产生程序、证书签发和验证程序、SSL连接测试程序以及其它的标准应用程。 Linux下OpenSSL的安装与使用 下载安装包 安装指令 ./config make make test sudo make install 测试代码 #include <stdio.h> #include <openssl/evp.h> int main(){ OpenSSL_add_all_algorithms(); return 0; } 运行截图 任务二 在Ubuntu中实现对实验二中的“wc服务器”通过混合密码系统进行防护 server.c #include <stdio

C 语言学习——错误处理

喜欢而已 提交于 2019-12-06 16:51:59
错误处理 c 语言不提供对错误处理的直接支持,但是作为一种系统编程语言,它以返回值的形式允许我们访问底层数据。在发生错误时,大多数的 C 或 UNIX 函数调用返回 1 或 NULL,同时会设置一个错误代码 errno,该错误代码是全局变量,表示在函数调用期间发生了错误。我们可以在 errno》h 头文件中找打各种的错误代码。 所以, C 程序可以通过检查返回值,然后根据返回值决定采取哪种适当的动作。开发人员应该在程序初始化时,把 errono 设置为 0 ,这是之中良好的编程习惯。0 值表示程序中没有错误。 来源: https://www.cnblogs.com/xushuhai/p/9556400.html

训练DQN,报错:OSError: [Errno 12] Cannot allocate memory

耗尽温柔 提交于 2019-12-06 16:37:13
训练DQN,报错:OSError: [Errno 12] Cannot allocate memory 问题介绍: 这两天在做强化学习的作业,使用 DQN 打 Atari 游戏,但在训练过程中,出现了题目中描述的错误。 解决方案: 参考链接( https://github.com/openai/gym/issues/110 ) (1)涉及知识:linux 的 overcommit_memory 、 overcommit_ratio overcommit_memory 是内核对内存分配的一种策略。 vm.overcommit_memory 共有三种取值,分别为 0, 1, 2 vm.overcommit_memory = 0: 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。 vm.overcommit_memory = 1: 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。 vm.overcommit_memory = 2: 拒绝等于或者大于总可用 swap 大小以及 overcommit_ratio 指定的物理 RAM 比例的内存请求。 overcommit_ratio 默认为 50,为物理内存分配时的比例。 只有当 vm.overcommit_memory = 2 的时候才会生效

让Libevent 在window下 支持 IOCP

一笑奈何 提交于 2019-12-06 12:54:14
Libevent 的强大就不说了,但由于在window下使用的是 select 机制 ,除了效率低下意外还有一个讨厌的"FD_SETSIZE"限制,所以一直 希望能支持IOCP,可是现在已经到2.0还是没能够支持。 无意中在网上发现了个支持IOCP的libevent版本,是1.4.7版的。不过没关系,把其中的一个关键文件"win32iocp.c"拷贝到最新的1.4.14b版本中,并在"event.c" 中修改: ..... #ifdef HAVE_POLL extern const struct eventop pollops; #endif #ifdef HAVE_EPOLL extern const struct eventop epollops; #endif #ifdef HAVE_WORKING_KQUEUE extern const struct eventop kqops; #endif #ifdef HAVE_DEVPOLL extern const struct eventop devpollops; #endif #ifdef WIN32 #ifndef _EVENT_NOIOCP extern const struct eventop win32iocpops; #endif extern const struct eventop win32ops;

UNIX编程 TCP基础读写笔记

让人想犯罪 __ 提交于 2019-12-06 12:20:34
基本TCP客户端与服务器 Server #include <cstdio> #include <cstring> #include <string> #include <vector> #include <unistd.h> #include <arpa/inet.h> #include <sys/errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <string> using namespace std; const int BUF_SIZE = 1024; string addr_to_string(const sockaddr_in *addr) { char addr_str[INET_ADDRSTRLEN]; const char *addr_str_ptr = inet_ntop(AF_INET, &addr->sin_addr, addr_str, sizeof(addr_str)); if (addr_str_ptr == NULL) { fprintf(stderr, "inet_ntop failed\n"); return ""; } return string(addr_str_ptr) + ":" + to_string(ntohs(addr->sin_port)); }