Skip to content

sem_open

果冻虾仁 edited this page May 9, 2015 · 1 revision

##函数原型

#include <fcntl.h>           /* For O_* constants */
#include <sys/stat.h>        /* For mode constants */
#include <semaphore.h>

sem_t *sem_open(const char *name, int oflag);
sem_t *sem_open(const char *name, int oflag,
                mode_t mode, unsigned int value);

##参数 和open()函数参数基本相同。唯一的限制是参数name必须是字符/打头。

Linux环境编程API

C语言API包含部分标准C的API、POSIX标准的系统编程API(一些Linux独有的系统API会单独注明)。

头文件源码

大部分头文件源码在/usr/include目录下。

安装man手册

因为涉及到大量的POSIX编程。所以最好下载POSIX函数的man手册。

Ubuntu

apt-get install manpages-posix        
apt-get install manpages-posix-dev

默认安装了manpages-dev,所以不装POSIX的man手册是可以查看绝大部分API的。
但是不装的话,有些API是不能看到的,比如posix_spawn函数。

CentOS

yum install man-pages.noarch

关于目录

左侧的目录并非以函数为索引依据,主要是以系统的man手册页面为索引依据。
比如exec里面包含6个函数、pipe里面包含pipe()和pipe2()两个函数,但是它们都是属于一个man页面中。

Clone this wiki locally