Chinaunix首页 | 论坛 | 博客
  • 博客访问: 180190
  • 博文数量: 54
  • 博客积分: 1831
  • 博客等级: 上尉
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-12 12:50
文章分类

全部博文(54)

文章存档

2009年(11)

2008年(43)

分类:

2008-05-12 23:33:39

We all want progress, but if you're on the wrong road, progress means doing an about-turn and walking back to the right road; in that case, the man who turns back soonest is the most progressive.

我们都需要进步,但是如果你走错了路,那么进步就意味着你在绕圈子,最终回到正确的路上来。这时候,最早走回来的人进步最大。


- C.S. Lewis

Chapter 1. UNIX System Overview

难点:
Files and Directories
至今都没有完全明白。
The UNIX file system is a hierarchical arrangement of directories and files. Everything starts in the directory called root whose name is the single character /.A directory is a file that contains directory entries. Logically, we can think of each directory entry as containing a filename along with a structure of information describing the attributes of the file. The attributes of a file are such things as type of fileregular file, directorythe size of the file, the owner of the file, permissions for the filewhether other users may access this fileand when the file was last modified. The stat and fstat functions return a structure of information containing all the attributes of a file. In Chapter 4, we'll examine all the attributes of a file in great detail.We make a distinction between the logical view of a directory entry and the way it is actually stored on disk. Most implementations of UNIX file systems don't store attributes in the directory entries themselves, because of the difficulty of keeping them in synch when a file has multiple hard links. This will become clear when we discuss hard links in Chapter 4.

输入和输出;
标准,buffered ,unbuffered.
特别要注意他们之间的区别,而且要搞明白每类有那些函数,因为他们都太基础了
Unbuffered I/O is provided by the functions open, read, write, lseek, and close. These functions all work with file descriptors.

Figure 1.4. List all the files in a directory
#include "apue.h"
 
#define BUFFSIZE    4096
 
int
main(void)
{
    int     n;
    char    buf[BUFFSIZE];
 
    while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
        if (write(STDOUT_FILENO, buf, n) != n)
            err_sys("write error");
        if (n < 0)
            err_sys("read error");
 
        exit(0);
}
注意,在apue中,很多程序都是正确的情况下返回0,错误返回-1
还有一个问题,是以前的,就是“apue.h“和的区别?
Figure 1.5. Copy standard input to standard output, using standard I/O
#include "apue.h"
 
int
main(void)
{
    int     c;
 
    while ((c = getc(stdin)) != EOF)
        if (putc(c, stdout) == EOF)
            err_sys("output error");
 
    if (ferror(stdin))
        err_sys("input error");
 
    exit(0);
}
注意包裹函数,将整个程序显的短小精干。
上面都已经说了,要注意三类函数的用法,有点苦恼的是他们都太多。


newline character   "\n".
We do this because the execlp function wants a null-terminated argument, not a newline-terminated argument.
fork函数的具体用法?
waitpid的具体用法?
Figure 1.7. Read commands from standard input and execute them
#include "apue.h"
#include
 
int
main(void)
{
    char    buf[MAXLINE];   /* from apue.h */
    pid_t   pid;
    int     status;
 
    printf("%% ");  /* print prompt (printf requires %% to print %) */
    while (fgets(buf, MAXLINE, stdin) != NULL) {
        if (buf[strlen(buf) - 1] == "\n")
            buf[strlen(buf) - 1] = 0; /* replace newline with null */
 
        if ((pid = fork()) < 0) {
            err_sys("fork error");
        } else if (pid == 0) {      /* child */
            execlp(buf, buf, (char *)0);
            err_ret("couldn't execute: %s", buf);
            exit(127);
        }
 
        /* parent */
        if ((pid = waitpid(pid, &status, 0)) < 0)
            err_sys("waitpid error");
        printf("%% ");
    }
    exit(0);
}


Control-D, or ^D, is the default end-of-file character.
什么是supplementary group IDs?
重点,也是难点:

1.9. SignalsSignals are a technique used to notify a process that some condition has occurred. For example, if a process divides by zero, the signal whose name is SIGFPE (floating-point exception) is sent to the process. The process has three choices for dealing with the signal
.Ignore the signal. This option isn't recommended for signals that denote a hardware exception, such as dividing by zero or referencing memory outside the address space of the process, as the results are undefined.
Let the default action occur. For a divide-by-zero condition, the default is to terminate the process.
Provide a function that is called when the signal occurs (this is called "catching" the signal). By providing a function of our own, we'll know when the signal occurs and we can handle it as we wish.
Many conditions generate signals. Two terminal keys, called the interrupt key often the DELETE key or Control-Cand the quit keyoften Control-backslashare used to interrupt the currently running process. Another way to generate a signal is by calling the kill function. We can call this function from a process to send a signal to another process. Naturally, there are limitations: we have to be the owner of the other process (or the superuser) to be able to send it a signal

又一个难点,Time Values 就一个感觉,复杂!

1.11  system calls and library functions (这个在里也有介绍)
1.12. SummaryThis chapter has been a short tour of the UNIX System. We've described some of the fundamental terms that we'll encounter over and over again. We've seen numerous small examples of UNIX programs to give us a feel for what the remainder of the text talks about.The next chapter is about standardization of the UNIX System and the effect of work in this area on current systems. Standards, particularly the ISO C standard and the POSIX.1 standard, will affect the rest of the text.
 



阅读(1149) | 评论(0) | 转发(0) |
0

上一篇:总结:告一段落

下一篇:[unix 教程]2

给主人留下些什么吧!~~