博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  APUE

Advanced Programming in the Unix Environment
摘要:到现在为止,我看过的书籍基本上是一脉相承的,逐渐深入计算机内部: · C语言深度解剖 ----- 这个是电子书,遇到问题还经常看一看 · C专家编程(Exptert C Programming) ----- 这个看过去就忘了,在图书馆借的书 · C traps and pitfalls ---- 这个也是在图书馆借的,翻译的书,基本上也不怎么记得了 · Linux C一站式编程 ----- 这本... 阅读全文

posted @ 2011-05-30 16:21 天地玄黄 阅读(891) 评论(1) 推荐(0)

摘要:Mutex:所有线程进行竞争。被Mutex锁住的资源,要么被锁住,要么不被锁住。不会有其他情况。 ReaderWriter Lock:有三种状态,read lock, write lock, unlock。read lock可以多个线程共享,write lock只能一个线程使用。 这两个锁的共同特点:MUST intitialized before use, destroyed before fr... 阅读全文

posted @ 2011-05-27 11:29 天地玄黄 阅读(173) 评论(0) 推荐(0)

摘要:process使用fork()函数产生一个和父进程一摸一样的子进程。然后再使用exec函数用另一个program代替这个子进程。这样就产生了两个进程。 而thread则使用pthread_create()函数产生一个新的thread,这个thread和以前的thread没有什么上下级的关系,并且它调用的是一个“函数”,不是一个独立的程序。 阅读全文

posted @ 2011-05-26 19:54 天地玄黄 阅读(286) 评论(0) 推荐(0)

摘要:在Linux中使用线程相关的东西就要使用到这个头文件,但这还不算。如果仅仅使用这个头文件,会出现错误: undefined reference to `pthread_create'collect2: ld returned 1 exit statusmake: *** [threadid] Error 1 之所以出现这样的错误,是因为我们没有链接相应的函数库。所以在编译的时候要加上 –lpth... 阅读全文

posted @ 2011-05-26 14:55 天地玄黄 阅读(12057) 评论(0) 推荐(1)

摘要:和 threads 相关的信息: · thread ID · register value · a stack · scheduling priority and policy · signal mask · errno variable · thread-specific data 很多threads 所共享的东西: · .text · global and heap memory · stac... 阅读全文

posted @ 2011-05-26 14:08 天地玄黄 阅读(247) 评论(0) 推荐(0)

摘要:1、在Unix系统中,signal是可以随时出现的。因此,Unix中的process就告诉kernel “如果出现signal,就去做下面这些事情”。 2、signal 是由谁发出的:terminal-generated signals, hardware exceptions, kill(2) function, kill(1) command, software condition sign... 阅读全文

posted @ 2011-05-26 13:56 天地玄黄 阅读(261) 评论(0) 推荐(0)

摘要:原文网址:http://uw714doc.sco.com/en/SDK_sysprog/_The_Controlling-Terminal_and_Pr.html The controlling-terminal and process-groups A terminal may belong to a process as its controlling-terminal, which is a... 阅读全文

posted @ 2011-05-13 15:30 天地玄黄 阅读(390) 评论(0) 推荐(0)

摘要:一个C语言的可执行程序(a.out)通常被分成以下几个部分: · Text segment: 即汇编中的.text segemnt。machine instruction, sharable, only one copy in memory, read-only · Initialized data: 即汇编中的.data segment。是已经初始化的数据。是出现在所有的程序之外的变量(全局变量... 阅读全文

posted @ 2011-05-06 15:28 天地玄黄 阅读(390) 评论(0) 推荐(0)

摘要:一般我们写main函数都是这样的: int main(int argc, char **argv); 一个process调用exec函数给新的将要执行的program传递command-line argument。(When a program is executed, the process that does the “exec” can pass command-line argument... 阅读全文

posted @ 2011-05-06 14:53 天地玄黄 阅读(171) 评论(0) 推荐(0)

摘要:C程序会使用 "start-up routine” 来调用main()函数,开始执行main() 函数。这个 "start-up routine”从kernel中获取参数和环境,然后设定好,然后调用main()函数开始执行。 当main()函数调用return 0; 返回的时候,返回的地方也是"start-up routine”。由start-up routine在执行一些操作(一般是调用exi... 阅读全文

posted @ 2011-05-06 10:44 天地玄黄 阅读(247) 评论(0) 推荐(0)

摘要:副标题: 在汇编中使用Standard C Library。 main函数的执行过程。 main函数与Standard C Library的交互。 C程序是怎么开始和结束的: 在这里,一个C程序就是一个process Note: The only way a program is executed by the kernel is when one of the exec functions is... 阅读全文

posted @ 2011-05-06 10:32 天地玄黄 阅读(765) 评论(0) 推荐(0)

摘要:1、Standard I/O是指ISO C的standard I/O library中的函数。 它是以stream为中心的,当我们使用standard I/O打开或者新创建一个文件的时候,我们就说为这个文件关联了一个stream(或者更近一步,就认为这个文件已经变成了一个stream). 2、UNIX中把所有的东西都看做文件,键盘也是一个文件。打开这个文件,就会返回这个文件的file descr... 阅读全文

posted @ 2011-05-05 10:57 天地玄黄 阅读(318) 评论(0) 推荐(0)

摘要:4.11 In Section 4.21, our version of ftw never changes its directory. Modify this routine so that each time it encounters a directory, it does a chdir to that directory, allowing it to use the filenam... 阅读全文

posted @ 2011-05-03 21:07 天地玄黄 阅读(620) 评论(0) 推荐(0)

摘要:4.6 Write a utility like cp(1) that copies a file containing holes, without writing the bytes of 0 to the output file. 我自己写了一整程序来完成这个操作。 首先要使用fig3.2的程序生成一个带有hole的文件file.hole。 #include "apue.h"#include... 阅读全文

posted @ 2011-05-03 15:28 天地玄黄 阅读(535) 评论(0) 推荐(0)

摘要:1、每一个file system都可以用major device number 和 minor device number来确定。major device number表示一个设备的device driver,比如一个磁盘就会有一个major device number。而minor device number则表示特定的subdevice。比如在一个磁盘上可以有多个文件系统,这些文件系统的ma... 阅读全文

posted @ 2011-05-03 11:25 天地玄黄 阅读(175) 评论(0) 推荐(0)

摘要:看一下UFS的构成。 1、每一个disk drive都可以分成好多小的partitions,每个partition都可以使用一种file system。在Unix世界中有各种各样的File system可供使用:UFS,PCFS,HSFS等等。这里介绍UFS。 看下图: 书上没有详细介绍各个细节,只是介绍了i-node。在这个file system中,i-node里存放了有关文件的几乎全部的信息... 阅读全文

posted @ 2011-05-01 15:20 天地玄黄 阅读(241) 评论(0) 推荐(0)

摘要:边看边记录一些这一章的要点 1、本章主要围绕三个函数来进行讲述:stat() fstat() lstat(),他们都是对一些文件进行信息获取,查看这个文件。第一个函数是最普通的函数,第二个函数是针对打开的文件进行信息获取,第三个函数则对synbolic links有特殊的处理。 2、File Types:Unix系统中有很多的文件类型,分类如下: · Regular file. 这是Unix系统... 阅读全文

posted @ 2011-05-01 11:19 天地玄黄 阅读(219) 评论(0) 推荐(0)

摘要:3.6 If you open a file for readwrite with the append flag, can you still read from anywhere in the file using lseek? Can you use lseek to replace existing data in the file? Write a program to verify t... 阅读全文

posted @ 2011-04-29 22:13 天地玄黄 阅读(369) 评论(0) 推荐(0)

摘要:1. 我目前在Linux中运行的程序通常是在Shell 之上运行的,Shell 已经设定好了 standard input(键盘) 和 standard output(显示器). 2. 许多程序都默认 standard input 的 file descriptor 是 0, standard output 的 file descriptor 是 1。在<unistd.h>中定义了两个常量来表示... 阅读全文

posted @ 2011-04-29 22:05 天地玄黄 阅读(221) 评论(0) 推荐(0)

摘要:本文简要介绍一下在Unix系统中的一些概念,这是Advanced Programming in Unix Enviroment 这本书的第一章的内容 Files 1、在Unix中创建一个新directory的时候,会自动创建两个filenames,即.(called dot) and ..(called dot-dot)。 2、每一个file都有一个File Descriptor。File descriptors are normally small non-negative integers that the kernel uses to identify the files being . 阅读全文

posted @ 2011-04-09 16:57 天地玄黄 阅读(373) 评论(0) 推荐(0)