作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我在使用 unix_error 函数时遇到了问题,我相信我没有包含特定的文件,但我似乎无法在互联网上找到我需要包含的文件。有什么建议吗?
编辑:我写了这样的东西..
while((pid = waitpid(-1, NULL, 0)) > 0){
printf("SERVER: Handler reaped child %d\n", (int) pid);
child_count--;
}
if(errno != ECHILD){
unix_error("waitpid error");
}
sleep(2);
return;
尝试编译 unix_error 时出现错误
最佳答案
没有标准函数unix_error()
。
出于多种目的,您可以使用此代码。
#ifndef UNIXERR_H_INCLUDED
#define UNIXERR_H_INCLUDED
extern void unix_error(const char *msg);
#endif /* UNIXERR_H_INCLUDED */
#include "unixerr.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void unix_error(const char *msg)
{
int errnum = errno;
fprintf(stderr, "%s (%d: %s)\n", msg, errnum, strerror(errnum));
exit(EXIT_FAILURE);
}
还有很多可以改进的地方。第一个方法是将程序名称添加到输出的开头。另一种方法是让函数支持可变长度参数列表,就像 printf() 那样。有些人不喜欢打印错误号;有些人不喜欢打印错误号。我更喜欢它。
关于c - c中unix_error函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23035413/
我是一名优秀的程序员,十分优秀!