

OS concept#
System call v.s Function call#

User mode v.s. Kernel mode#

- Hardware always in Kernel Mode
Horizontal#
- Services for Application Programs: User Identification, Process Management, Memory Management, File/Directory Management, Inter-process Communication, Signal, I/O Management (e.g., Terminal, Network, etc), …
- OS Kernel: CPU Scheduling, Virtual Memory, File System, Protection, Security, Synchronization, I/O Control, …
User identification#
User 是一種權限,不一定是真實使用者
在 /etc/passwd(local host or NIS DB)裡面記錄
cat /etc/passwdbash可以取得資訊,每個 row 是一個 User,format 是:
{User-name}:{Passwd}:{User-Id}:{Group-id}:{Comment}:{Home-dir}:{Shell}plaintextroot:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin/false
_uucp:*:4:4:Unix to Unix Copy Protocol:/var/spool/uucp:/usr/sbin/uucico
_taskgated:*:13:13:Task Gate Daemon:/var/empty:/usr/bin/false
_networkd:*:24:24:Network Services:/var/networkd:/usr/bin/false
_installassistant:*:25:25:Install Assistant:/var/empty:/usr/bin/falsebashcrypt()- 是一個 one-way func,用於登入帳號
- 第一個參數
{passwd}是真正的密碼 - 第二個參數
{salt bit}是為了製造同樣 common word 隨機性,System 會選擇 time-base 的參數 -
bashcrypt("apple", "am") → "amADBMNoVAZpc" crypt("water", "pm") → "pmRarHxhhU34U" - 系統使用你的帳號跟你輸入的密碼放入比對
man 3 crypt可以查看
Process Management#
- Program is a executable file
- Process is an executing instance of a program
psis a snapshot of the current processtopis display processes
CPU Scheduling#
- Time Sharing: the rate is too fast that user won’t realize that they are sharing

- Event can be DISK
- (IMPROTANT) A process want to inline of ready queue, it has to put every data into the memory.

Context Switch
- Time Slice maybe just a nano second
- We have to store the status of last process before kicking.
- Then we have to restore the status of the next process.
- Memory is too slow, so we have L1, L2 cahce on CPU.
- If one process want to ask DISK, CPU will kick out this process into event, but not time slice.

- Exit have many kind.

UNIX Process#

From “init” prcess use fork to build a process tree.

Pipe
- A way to send the output of one command to the input of another Filter
- A program that takes input and transforms it in some way
wc-gives a count of words/lines/charsgrep-searches for lines with a given stringmoresort-sorts lines alphabetically or numerically
bashls -la | more
bashcat file | wc
bashman ksh | grep “history”
bashls -l | grep “bowman” | wc
bashwho | sort > current_users
UNIX philosophy:
- Write programs that do one thing and do it well
- Write programs that work together
- Write programs that handle text streams, because that is the universal interface
Memory Management#

File/Directory Management#
File Structure#

- root
/: all unix like system’s root. - lib: library, the include path
- bin: binary, in the system genuinly
- var: dynamic file

chmod <mode> <file(s)>
chmod 700 file.txt
chmod g+rw file.txtbashchmod,chown,touch
Back to the content
NTU PJ System Programming
2025 Fall
← Back to the content