您的位置:首页 > 产品设计 > UI/UE

读书笔记-APUE第三版-(2)UNIX标准和实现

2014-04-22 17:41 309 查看

UNIX标准

ISO C

ISO C是C语言标准,目的是增强C语言程序在各种系统间的移植性,不局限于UNIX。C标准已经更新到2011版,目前系统实现才勉强追上C99标准。(ANSI C对应C89标准)

IEEE POSIX

POSIX代表Portable OperatingSystem Interface,由IEEE制定,目的是标准化各种UNIX操作系统接口。

The Single UNIX Specification

POSIX的扩展超集,由Open Group发布。Open Group拥有UNIX商标,负责认证Unix系统。

FIPS

FIPS代表Federal InformationProcessing Standard,由美国政府发布,用于采购计算机系统,基于IEEE Standard 1003.1-1988和ANSI C。

UNIX系统实现

时间线

下图引用自第一版(1992年)



第三版讲解的四个操作系统:

FreeBSD基于4.4BSD-Lite系统。
 Linux是开源类UNIX操作系统,诞生于1991年
 Mac OS X内核Darwin基于Mach Kernel、FreeBSD等。
 Soloris基于System VRelease 4。

Limits

系统资源限制包括两种类型:

编译时限制,编译时限制定义在一系列头文件中,如<limits.h>
运行时限制,通过sysconf函数获取系统运行时资源限制,如_SC_CHILD_MAX(通常以_SC开头)。通过pathconf/fpathconf函数获取和特定文件目录相关的限制值,如_PC_PATH_MAX(通常以_PC开头)。

#include<unistd.h>
long sysconf(int name);
long pathconf(const char *pathname, int name);
long fpathconf(int fd, int name);
All three return: corresponding value if OK, −1 on error (see later)


功能测试宏

头文件中包含各种值,包括POSIX和XSI标准的定义,也包括各种系统相关值。使用_POSIX_C_SOURCE和_XOPEN_SOURCE,告诉编译器强制使用POSIX和XSI标准定义值。

gcc -D_POSIX_C_SOURCE=200809L file.c
gcc -D_XOPEN_SOURCE=700-std=c99 file.c -o file


基本数据类型

考虑到移植性,<sys/types.h>中定义了各种数据类型

Type

Description

clock_t

counter of clock ticks (process time) (Section 1.10)

comp_t

compressed clock ticks (not defined by POSIX.1; see Section 8.14)

dev_t

device numbers (major and minor) (Section 4.24)

fd_set

file descriptor sets (Section 14.4.1)

fpos_t

file position (Section 5.10)

gid_t

numeric group IDs

ino_t

i-node numbers (Section 4.14)

mode_t

file type, file creation mode (Section 4.5)

nlink_t

link counts for directory entries (Section 4.14)

off_t

file sizes and offsets (signed) (lseek,Section 3.6)

pid_t

process IDs and process group IDs (signed) (Sections 8.2 and 9.4)

pthread_t

thread IDs (Section 11.3)

ptrdiff_t

result of subtracting two pointers (signed)

rlim_t

resource limits (Section 7.11)

sig_atomic_t

data type that can be accessed atomically (Section 10.15)

sigset_t

signal set (Section 10.11)

size_t

sizes of objects (such as strings) (unsigned) (Section 3.7)

ssize_t

functions that return a count of bytes (signed) (read, write,Section 3.7)

time_t

counter of seconds of calendar time (Section 1.10)

uid_t

numeric user IDs

wchar_t

can represent all distinct character codes

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apue unix 操作系统