【APUE】Chapter1 UNIX System Overview

这章内容就是“provides a whirlwind tour of the UNIX System from a programmer's perspective”。shell

其实在看这章内容的时候,已经先看过了Chapter7~Chapter13,回头再看看这样的综述介绍。多线程

 

1.2 UNIX Architectureapp

  主要就了解下面这张图便可:ide

  

  在通常UNIX operating system中谁在哪层来调用谁。函数

 

1.3 Logging Inui

  操做系统根据/etc/passwd中的信息来判断logging in信息是否匹配。spa

  每一行表明一个用户登陆信息,举例:操作系统

  

  通常分为七个部分,用冒号分割:线程

    login name3d

    encrypted password

    numeric user ID

    numeric group ID

    a comment field(这个field在例子中为空)

    home directory

    shell programm

 

1.4 Files and Directories

  这个部分给出了第一份代码的例子。经过这个20行代码的例子,交代了很多东西:

    man命令怎么用

    头文件apue.h是干啥的

    错误处理函数err_sys和err_quit函数都是干啥的

    ...

  看了以后,给个人感受是做者安排每一个例子都是用心的,尤为在书一开始的地方都把一些书上以后经常使用的内容交代清楚,让人看的很明白。

 

1.5 Input and Output

  (1)File Descriptors定义(先记着,有个念想): "normally small non-negative integers that the kernel uses to identify the files accessed by a process. Whenever it opens an existing file or creates a new file, the kernel returns a file descriptor that we use when we want to read or write the file."

  (2)Standard Input , Standard Output & Standard Error

  (3)Unbuffered I/O:open read write lseek close都是,而且这些函数都跟file descriptors协做。看到这里对书上的例子瞬间产生了一个误解:不是说是unbuffered了么,怎么还有read(STDIN_FILENO, buf, BUFFSIZE)这样的形式呢?我没有看事后面的部分,可是猜想这里说的unbuffered是不用fflush刷新缓冲区的,具体的后面再看。

  (4)Standard I/O:就是提供了一个buffered的接口来调用各类unbuffered I/O函数,函数包含在头文件<stdio.h>中。

 

1.6 Programs and Processes

  (1)Program:磁盘上的可执行文件;执行的时候先读入内存,而后由kernel调用exec函数执行之。

  (2)Processes and Process ID:正在执行的program示例就叫process;unix系统的进程号非负整数

  (3)Process Control:fork ,exec, waitpid

  (4)Thread and Thread IDs

 

1.7 Error Handling

  (1)通常遇到error了,unix系统就返回一个负整数;不一样的负整数标示不一样类型的错误

  (2)<errno.h>头文件中有“symbol errno and constants for each value that errno can assume”,每一个符号都以E开头;能够用man 3 errno来查看具体表明意思。

  (3)考虑到多线程的状况,是贡献进程中的address space的,每一个线程要有独立的errno就须要其余的定义方法,以下图:

    

    具体参考的是/usr/includes/bits/errno.h头文件中的定义

  (4)strerror函数把错误变量映射到错误信息字符串;perror能够接受一个参数(通常是program的名),并将出错信息输出到standard error上。

  (5)error recovery。fatal error么有recovery action;nonfatal error有recovery action。跟资源相关的nonfatal error的recovery的策略分两种:一种是等;一种是重试。

  

1.8 User Identification

  

1.9 Sginals

  Signals are a technique used to notify a process that some condition has occurred

 

1.10 Time Values

  unix系统有两类不一样的时间变量:

    (1)Calendar time:1970.1.1零点开始到如今的秒数

    (2)Process time:CPU time(在多线程那章的时候用到过

  注意相对时间和绝对时间;另外若是是多核的条件,时间统计时候与单核的状况可能不同

 

1.11 System Calls and Library Functions

   具体能够参照1.2中的那张图理解。对于application的级别来讲,便可以直接用system call也能够用libarary functions。

   书上举了一个内存分配的malloc(2)函数与sbrk(3)的例子。

相关文章
相关标签/搜索