unistd.h
unistd.h是unix std的意思,是POSIX标准定义的unix类系统定义符号常量的头文件,
包含了许多UNIX系统服务的函数原型
unistd.h在unix中类似于window中的windows.h!
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
unistd.h含有的常量与函数:
ssize_t read(int, void *, size_t); // 读取文件使用
int unlink(const char *);
ssize_t write(int, const void *, size_t); // 写文件
int usleep(useconds_t); // 进程休眠,单位为微妙
unsigned sleep(unsigned); // 进程休眠,单位为秒 int access(const char *, int); // 获取文件的权限
unsigned alarm(unsigned);
int chdir(const char *);
int chown(const char *, uid_t, gid_t);
int close(int); // 关闭文件
size_t confstr(int, char *, size_t);
void _exit(int);
pid_t fork(void); NULL // Null pointer
SEEK_CUR // Set file offset to current plus offset.
SEEK_END // Set file offset to EOF plus offset.
SEEK_SET // Set file offset to offset.
在进行堵塞式系统调用时。为避免进程陷入无限期的等待,能够为这些堵塞式系统调用设置定时器。Linux提供了alarm系统调用和SIGALRM信号实现这个功能。
SIGALRM信号成功安装后,在什么情况下进程会收到该信号呢?这就要依赖于Linux提供的定时器功能。在Linux系统下,每一个进程都有惟一的一个定时器,该定时器提供了以秒为单位的定时功能。在定时器设置的超时时间到达后,调用alarm的进程将收到SIGALRM信号。
void main()
{
//安装SIGALRM信号
if(signal(SIGALRM,CbSigAlrm)==SIG_ERR)
{
perror("signal");
return;
}
//关闭标准输出的行缓存模式
setbuf(stdout,NULL);
//启动定时器
alarm();
//进程进入无限循环,仅仅能手动终止
while()
{
//暂停,等待信号
pause();
}
}
alarm函数的使用:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h> static int flag = ;
void handle(int signum){
printf("hello world %d\n", flag++);
alarm();
} int main() {
alarm();
signal(SIGALRM, handle);
while();
}
unistd.h的更多相关文章
- sys/types.h fcntl.h unistd.h sys/stat.h
sys/types.h 是Unix/Linux系统的基本系统数据类型的头文件,含有size_t,time_t,pid_t等类型. 在应用程序源文件中包含 <sys/types.h> 以访问 ...
- #include<unistd.h>头文件的理解
1.百度百科定义 unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称.该头文件由 POSIX.1 标准(单一UNIX规范的基础)提出,故 ...
- vc编程时说“Cannot open include file: 'unistd.h': No such file or directory”
本文专自http://blog.csdn.net/mangobar/article/details/6314700 unistd.h是unix standard header之意,因此,Linux下开 ...
- #include<unistd.h>存在linux中,含有系统服务的函数
#include<unistd.h> linux标准库#include <unistd.h>与windows的#include <windows.h>(C语言开发) ...
- VS 2015 报错 " 'unistd.h': No such file or directory" 的解决办法
使用 Visual Studio 2015 进行程序开发工作时,如果编译的是来自于Linux平台的源文件,该源文件可能会包含头文件 uninstd.h,这样会产生报错信息: "fatal e ...
- unistd.h文件
转载地址:http://baike.baidu.com/link?url=nEyMMFYevs4yoHgQUs2bcfd5WApHUKx0b1ervi7ulR09YhtqC4txmvL1Ce3FS8x ...
- #include <unistd.h> 的作用
原文:http://blog.csdn.net/ybsun2010/article/details/24832113 由字面意思,unistd.h是unix std的意思,是POSIX标准定义的uni ...
- <unistd.h>的close(0)导致std::cout被关闭
代码如下:其中ZJ::open_max返回系统允许的打开的文件的最大个数 #include "util.h" #include <unistd.h> // int cl ...
- windows 无法找到unistd.h 的解决方法
//#include <unistd.h> #ifndef _UNISTD_H #define _UNISTD_H #include <io.h> #include < ...
随机推荐
- Android SDK Manager for Mac 在线更新镜像地址截至2017-10-01亲测有效
虽然国内google被墙了,但仍可利用国内的某些镜像网站实现Android SDK在线更新,使用方法如下: 1.启动 Android SDK Manager ,打开主界面,依次选择『Tools』.『O ...
- Jmeter上传附件EXCEL
1.通过对上传附件接口进行抓包,获取的信息如下: 2.在jmeter脚本中添加http请求,并添加http请求头信息如下: 3.在http请求中添加上传附件的内容如下,由于我上传的是excel,所以M ...
- java消息服务学习之JMS概念
JMS即Java消息服务(Java Message Service)应用程序接口是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送消息,进行异步通信. ...
- ROS机器人编程实践----琐碎知识点
amcl原理: amcl将激光传感器数据与从地图预估的传感器数据相比较,给出可能的位姿.如果传感器数据和某个候选位姿处的预测数据相同,amcl就会给这个位姿一个较高的概率,反之,就会降低这个概率.概率 ...
- 读取本地json文件,并转换为dictionary
// 读取本地JSON文件 - (NSDictionary *)readLocalFileWithName:(NSString *)name { // 获取文件路径 NSString *path = ...
- 泛型集合List的详细用法
命名空间: System.Collections.Generic List<T>类是 ArrayList 类的泛型等效类. 该类使用大小可 按需动态增加 的数组实现 IList& ...
- 【POJ 2176】Folding
[原题链接]传送门 [题面大意] 一个字符串,可以将它改写成循环节带括号的形式进行压缩,输出压缩长度最小的字符串. [题解思路] 1.没思路没思路,不知道怎么乱搞,大概就可以想到动态规划. 2.套路区 ...
- 论文笔记:Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells
Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells 2019-04- ...
- redis 执行操作时提示(error) NOAUTH Authentication required.
(error) NOAUTH Authentication required. 出现认证问题,设置了认证密码,输入密码即可 127.0.0.1:6379> auth 123456
- Lintcode225-Find Node in Linked List-Naive
225. Find Node in Linked List Find a node with given value in a linked list. Return null if not exis ...