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產生一個新的process丐怯,因為我們可以說shell是這些processes的parent喷好。shell 本身是init process的child process。(一些命令不會產生新的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)。然后后面產生的任何file和process都會有這個user id 和 group id在上面矛洞。GID的意義在于確定用戶能夠使用哪些shared files and commands洼哎。