What is Unix
Unix is a Multi-user, multi-process and multi-access operating system.
這三個multiple其實是互不影響的(orthogonal),像x, y, z軸一樣。
先來說說unix的歷史,Unix在20世紀60年代中晚期誕生于AT&T的貝爾實驗室中。最初發(fā)布的Unix中的一些重要設計因素到如今都還在使用:
其中一個設計是“Unix哲學”,建立小的模塊化的應用,只做一件事情并把它做好。可以通過combine多個簡單的小命令來完成復雜的工作。
另一個是單一文件結構,程序可以通過它互相通訊。這也是為什么在Linux里說“一切都是文件”-包括硬件設備文件,和提供系統(tǒng)信息及其他數(shù)據(jù)的特殊文件。
unix中只有file 和 process。all devices are represented by file。-------一切皆文件
file disk,devices,input 和 output of commands 都被看作文件。
對所有文件(目錄、字符設備、塊設備、 套接字、打印機等)操作,讀寫都可用fopen()/fclose()/fwrite()/fread()等函數(shù)進行處理。屏蔽了硬件的區(qū)別,所有設備都抽象成文件,提供統(tǒng)一的接口給用戶。這就是“一切皆是文件”的思想。
The fundamental component of information in Unix is the byte stream. It allows files, devices and even programs to be used interchangeably as the source or destination of data; and thus allows the underlying machine architecture to be hidden from the user.
文件是被動(passive)的entity,允許寫入和輸出。進程是積極的(active)的entity,進程的起點都是一個文件,當被執(zhí)行的時候才變成進程。進程都是有生命的。
UNIX主要有:
command line user interface
can combine simple command to realize complex commands
hierarchical file system
TREE FOR FILE & PROCESS
Unix File System(UFS): inverted tree, single root directory which contains files. *Unix system contains only one file system。但是這個file system是可以擴展的,可以連接很多其他的tree。所以最終看起來還是一個tree。因為只有一個tree,所以所有文件都在一個name space上。
Process tree :process tree, all processes have a parent process and may have child process. every process has a PID (process ID) and PPID (parent process ID).
第一個process叫做init,它是init machine to make it ready for user的過程的一部分。init創(chuàng)建了一個child process to set up machine and prompt user to login. 一旦user login了,有一個新的child process被創(chuàng)建了,用來讓用戶輸入命令,這個新的child process就是shell。對于每一個用戶輸入的命令,shell產(chǎn)生一個新的process,因為我們可以說shell是這些processes的parent。shell 本身是init process的child process。(一些命令不會產(chǎn)生新的process,例如ls)
What are Users
users are owners of files and processes, so in Unix everything(file+process) carries a UID(User ID) and GID(group ID).
user一定需要先login才能使用unix系統(tǒng),通過login,系統(tǒng)會確定用戶信息,然后verify用戶可以access的資源和associate的文件。明確地說,user會被放在整個file system的一個sub-system上然后被給一個initial process。
當user第一次login的時候,他們會得到initial process(shell)和file(home directory)。然后后面產(chǎn)生的任何file和process都會有這個user id 和 group id在上面。GID的意義在于確定用戶能夠使用哪些shared files and commands。