2013年12月26日 星期四

[ICA] 演講筆記


電腦動畫概論,演講資料如下:
 
時 間:12月27日星期五 13:20 ~ 15:10
地 點:工程三館EC015
主講人:翁士欽,西基電腦動畫股份有限公司
講 題:From School to Industry–Engineering for Computer Animation
主持人:林文杰 教授
====================

2013年12月25日 星期三

[IOS] HW3 Virtual address translation and COW in fork


這次的作業需求分成兩個 task:

Task 1
Implement a custom system call to translate a virtual address to physical
address.

Task 2
Verify that "fork" uses copy-on-write in the creation of child process address
space.


2013年12月16日 星期一

[SA] Hw4 FAMP(FreeBSD+Apache+MySQL+PHP)










  • # 先從 devel/git 的 ports 中安裝 git
  • # 同時間選取 gitweb 以提供網頁界面
  • # 之後遇到的設定頁照原來的 OK OK 就可以
  • cd /usr/ports/devel/git
  • make install clean
  •  
  • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
  • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
  • pw groupadd -n git -g 9418
  • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
  •  
  • # 新增 repo (倉庫 work),並更改屬性
  • chown git:git /home/git
  • chmod 755 /home/git
  •  
  • mkdir /home/git/work/
  • chmod 775 /home/git/work/
  • chown git:git /home/git/work/
  •  
  • # 設定除了 commit 外還可以使用額外指令的用戶
  • # 如果使用者只需要 commit,就可以不加進來
  • vi /etc/group
  • git:*:9418:zeuxis,neo
  •  
  • # 設定 SSH 認證金鑰,因為 git 要用到這東西
  • # 每個使用者的 SSH Key 也要加進 authorized_keys.
  • # 每個 key 為一行
  • mkdir /home/git/.ssh/
  • chmod 700 /home/git/.ssh/
  •  
  • touch /home/git/.ssh/authorized_keys
  • chmod 600 /home/git/.ssh/authorized_keys
  • chown -R git:git /home/git/.ssh/
  •  
  • # 生成指定用戶的 SSH Key
  • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
  • # 另還可用 ssh-keygen -t rsa 生成 rsa
  • # 生成時 Enter passphrase 無視按下 enter 即可
  • su username
  • ssh-keygen -d
  • su root
  • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
  •  
  • # 接著設定 git 的 repo
  • mkdir /home/git/work/test.git
  • cd /home/git/work/test.git && git init --bare --shared
  •  
  • # 接著進行一個簡單的測試
  • mkdir /tmp/test && cd /tmp/test && git init
  • echo "This is a test" > index.html
  • git add
  • git commit -m 'added index.html'
  •  
  • # 之後 commit 到遠端的 repo
  • git remote add origin username@example.com:work/test.git
  • git push origin master
  •  
  • # 之後再設定 gitweb
  • mkdir /home/git/public_html
  • chmod 755 /home/git/public_html
  • chown git:git /home/git/public_html
  • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
  •  
  • # 再設定 apache
  • <VirtualHost *:80>
  •   ServerAdmin no-reply@example.com
  •   DocumentRoot "/home/git/public_html"
  •   ServerName git.example.com
  •  
  •   <Directory "/home/git/public_html">
  •     Options ExecCGI
  •     Order allow,deny
  •     Allow from all
  •  
  •     DirectoryIndex gitweb.cgi
  •     AddHandler cgi-script .cgi
  •   </Directory>
  • </VirtualHost>
  •  
  • # 之後再編輯 gitweb.cgi
  • our $projectroot = "/home/git/work";
  • our $home_link_str = "work";
  • our $site_name = "git.example.com"
  • our $projects_list_description_width = 40; # 調整 description 空間
  •  
  • # 修改 test.git 的描述
  • echo "test.git" > /home/git/work/test.git/description
  •  
  • # 修改 test.git 的 owner
  • vim /home/git/work/test.git/config
  •  
  • # 在其後面加入
  • [gitweb]
  • owner = zeuxis
  • url = git://git.example.com/work/test.git
  • url = username@git.example.com:work/test.git
  •  
  • # 最後就是設定 Git protocol
  • # 在 /etc/rc.conf 最後加入這段
  • git_daemon_enable="YES"
  • git_daemon_directory="/home/git"
  • git_daemon_flags="--syslog --base-path=/git --export-all"
  •  
  • # 之後啟動 Git Daemon
  • /usr/local/etc/rc.d/git_daemon start
  •  
  • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
  • # 送出後接兩下 Enter 結束即可
  • /usr/local/etc/rc.d/git_daemon start &
  •  
  • # 檢查是否在執行
  • ps -eaf | grep -v grep | grep git
  •  
  • # 如有東西就可以再測試可否使用了
  • cd /tmp/test
  • rm -Rf *
  • git clone git://git.example.com/work/test.git
  • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf

    Requirement

    • To do this homework , you need 2 domain name.
      • http://twbbs.org/
      • http://www.nctucs.net/
    • You need two hostnames use same IP address.
    • When access http://yourdomain1, it will show the php information.
    • When access http://yourdomain1/sademo.html, it will show the text “This page is for sa demo.”. 
      • Notice that user can use both http and https portocal to access this page.
    • When access http://yourdomain1/private/, user need enter id "nctucs" and password "sahw4" which is implemented by .htaccess. And it will show the text “It’s my secret.”
    • System user sysadm can put file at ~/WWW/ and others can access it by visiting http://yourdomain1/~sysadm/. sysadm's password is your student id.
    • Your git website url is http://yourdomain2/gitweb
    • For demo, you need to put a git repository named “sademo.git”. And it’s decription is “This repository is for sa demo.”.
    • On your website, enter the sademo.git will show URL information, it’s URL is http://yourdomain2/gitweb/sademo.git.
    • You can clone and push your repository by http://yourdomain2/gitweb/sademo.git and password is your student id.
    • Users use cookie authentication when access your phpMyAdmin site http://yourdomain1/phpMyAdmin/
      • (You need to add a MySQL user for authentication).
      • Create another user with limited privilege
      • And notice that if others access http://yourdomain2/phpMyAdmin/, they can not access it.
      • Only 140.113.*.* can access it
      • But 140.113.235.* can’t access it
    • Redirect http://yourdomain1/ILoveSA to http://help.cs.nctu.edu.tw/ 
      • But http://yourdomain2/ILoveSA will not redirect .

    2013年12月2日 星期一

    [SA] Hw3 shell programming



    因為這次都是寫 code ,所以我這次就把 code 丟上 GitHub

    ================================================

    2013年11月10日 星期日

    [IOS] Ch6 Synchronization #1


    A cooperating process is one that can affect or be affected by other processes executing in the system. Cooperating processes can either directly share a logical address space (that is, both code and data) or be allowed to share data only through files or messages. The former case is achieved through the use of threads, discussed in Chapter 4. Concurrent access to shared data may result in data inconsistency, however. In this chapter, we discuss various mechanisms to ensure the orderly execution of cooperating processes that share a logical address space, so that data consistency is maintained.

    2013年11月9日 星期六

    [IOS] Ch5 Process scheduling

    Basic concept

    • In a single-processor system, only one process can run at a time
      • Any others must wait until the CPU is free and can be rescheduled.
    • Multiprogramming is to have some process running at all times to maximize CPU utilization. 
      • A process is executed until it must wait, typically for the completion of some I/O request. 
      • Several processes are kept in memory at one time, when one process has to wait, the operating system takes the CPU away from that process and gives the CPU to another process. 
      • Every time one process has to wait, another process can take over use of the CPU.
      • Scheduling of this kind is a fundamental operating-system function.
      • Almost all computer resources are scheduled before use. The CPU is, of course, one of the primary computer resources. Thus, its scheduling is central to operating-system design.

    2013年11月8日 星期五

    [IOS] Ch4 Multithreaded Programming


    • A thread is a basic unit of CPU utilization
    • Comprises
      • a thread ID
      • a program counter
      • a register set
      • a stack. 
    • Shares with other threads belonging to the same process
      • code section
      • data section
      • other operating-system resources(such as open files and signals)
    • A traditional (or heavyweight) process has a single thread of control.
    • If a process has multiple threads of control, it can perform more than one task at a time.
    • multiprocess 的 overhead 比 multithreaded 大

    2013年11月7日 星期四

    [IOS] Ch3 Process Concept


    Process Concept

    • An operating system executes a variety of programs: 
      • Batch system – jobs
      • Time-shared systems – user programs or tasks
    • Textbook uses the terms job and process almost interchangeably
    • Process – a program in execution; process execution must progress in sequential fashion

    2013年11月6日 星期三

    [IOS] Ch2 System Structures #3


    Virtual Machines

    • A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware
    • A virtual machine provides an interface identical to the underlying bare hardware
    • The operating system host creates the illusion that a process has its own processor and (virtual memory)
    • Each guest provided with a (virtual) copy of underlying computer

    2013年11月5日 星期二

    [IOS] Ch2 System Structures #2

     

    Types of System Calls

    • Process control
      • end, abort
      • load, execute
      • create process, terminate process
      • get process attributes, set process attributes
      • wait for time
      • wait event, signal event
      • allocate and free memory
    • File management
      • create file, delete file
      • open, close
      • read, write, reposition
      • get file attributes, set file attributes
    • Device management
      • request device, release device
      • read, write, reposition
      • get device attributes, set device attributes
      • logically attach or detach devices
    • Information maintenance
      • get time or date, set time or date
      • get system data, set system data
      • get process, file, or device attributes
      • set process, file, or device attributes
    • Communications
      • create, delete communication connection
      • send, receive messages
      • transfer status information
      • attach or detach remote devices
    • Protection

    [IOS] Ch2 System Structures #1


           We can view an operating system from several vantage points. One view
    focuses on the services that the system provides; another, on the interface that it makes available to users and programmers; a third, on its components and their interconnections. In this chapter, we explore all three aspects of operating systems, showing the viewpoints of users, programmers, and operating-system designers. We consider what services an operating system provides, how they are provided, how they are debugged, and what the various methodologies are for designing such systems. Finally, we describe how operating systems are created and how a computer starts its operating system.


    -- Operating System Concepts 8th, by Silberschatz, Galvin, Gagne


    2013年11月2日 星期六

    [SA] Hw2 ftp

    SA HW2 DEMO 流程說明

    ===================
    注意: 先在下列位置事先放置檔案供 demo 測試
    -----------------------------------------
    /home/ftp/public/
    /home/ftp/hidden/
    /home/ftp/hidden/treasure

    使用的 ftp 是 proftpd,FreeBSD 9.2-RELEASE

    ZFS

    ZFS on /home/ftp
    Create a zfs file system with mirror
    Do zfs snapshot
    Do zfs rollback
    Set compression
    Reboot and everything is fine (zfs still mount)



    2013年10月26日 星期六

    [SA] ProFTPd



    因為有人推薦 ProFTPd,所以這次就捨棄 PureFTPd 來用用看 ProFTPd 吧。

    先來簡介一下 ProFTPd 。

    ProFTPD (short for Pro FTP daemon) is a FTP server. ProFTPD is Free and open-source software, compatible to Unix-like systems and Microsoft Windows (via Cygwin). Along with vsftpd and Pure-FTPd, ProFTPD is among the most popular FTP servers in UNIX-like environments today. Compared to those, which focus e.g. on simplicity, speed or security, ProFTPD's primary design goal is to be a highly feature rich FTP server, exposing a large amount of configuration options to the user.

    ProFTPd 在 FreeBSD 裏面的位置是 /usr/ports/ftp/proftpd
    cd 到那裡然後 make install clean 之後就能順利安裝了:D


    [SA] ZFS

    ZFS 概觀

    ZFS 是 Sun Microsystems 為 Solaris 作業系統 (Unix 的一支) 開發的檔案系統。
    ZFS 具備 logical volume management 的能力 (稱為 Zpool)、也提供快照(snapshots)、copy-on-write 副本與自動修復的功能。

    不同於傳統的檔案系統是建立在單一的磁碟分割之上,ZFS 是建立在虛擬的儲存池(pool)之上,稱為 Zpool。Zpool 可以是由多個 volume 所組成,之後檔案系統再透過 zpool 取得使用空間。ZFS的另一項特點就是 128 位元的設計,理論上可以 2 的 48 次方個檔案,每個檔案最大可以有 16EB,最大單一 volume 可達 16EB。

    在資料安全與穩定性方面,ZFS 採用 copy- on-write 與 snapshots 計術來進一步維護檔案系統的正確性。所謂 copy-on-write 簡單的說就是每當檔案有變更時,不是直接覆蓋舊 有的資料,而是將使用中的區塊複製出來,而這些變更是在這複製的區塊上。Copy-on-Write 最大的好處就是當資料變更時,舊有的資料依然能夠維持,方便作為復原之用。Snapshot 就是保存著這些就有資料的映像副本的技術。ZFS 有著另一項先進的計術,就是透過刪除重複的資料 (Deduplication) 來節省儲存的空間。


    2013年10月22日 星期二

    [IOS] Ch1 Introduction note #3


    Process Management

    • A process is a program in execution. It is a unit of work within the system. Program is a passive entity, process is an active entity.
    • Process needs resources to accomplish its task
      • CPU, memory, I/O, files
      • Initialization data
    • Process termination requires reclaim of any reusable resources
    • Single-threaded process has one program counter specifying location of next instruction to execute
      • Process executes instructions sequentially, one at a time, until completion
    • Multi-threaded process has one program counter per thread
    • Typically system has many processes, some user, some operating system running concurrently on one or more CPUs
      • Concurrency by multiplexing the CPUs among the processes / threads

    2013年10月12日 星期六

    [IOS] Ch1 Introduction note #2


    Caching

    • Important principle, performed at many levels in a computer (in hardware, operating system, software)
    • Information in use copied from slower to faster storage temporarily
    • Faster storage (cache) checked first to determine if information is there 
      • If it is, information used directly from the cache (fast)
      • If not, data copied to cache and used there
    • Cache smaller than storage being cached
      • Cache management important design problem
      • Cache size and replacement policy

    2013年10月11日 星期五

    [IOS] Ch1 Introduction note #1


    Overview

           An operating system acts as an intermediary between the user of a
    computer and the computer hardware. The purpose of an operating
    system is to provide an environment in which a user can execute
    programs in a convenient and efficient manner.

            An operating system is software that manages the computer hard-
    ware. The hardware must provide appropriate mechanisms to ensure the
    correct operation of the computer system and to prevent user programs
    from interfering with the proper operation of the system.


    2013年10月9日 星期三

    [C] argc & argv



    一般來說 main function 長這樣:

    int main(int argc, char *argv[])

    其中,argc 代表的是參數個數,argv[argc] 代表的是指向參數,以下就用簡單的小程式來解釋。

    2013年9月29日 星期日

    [SA] Portsnap - Fetch: Requested Range Not Satisfiable


    因為下 portsnap 的時候按了 Ctrl + c,結果後來再下的時候就噴了 Fetch: Requested Range Not Satisfiable。

    只要 rm /var/db/portsnap/* 之後再下這個指令即可。

    Reference:https://149.20.54.209/showthread.php?t=39933

    [OS] 紀錄用連結


    這學期修了作業系統概論,找到中文的解釋網頁:

    http://www.csie.ntnu.edu.tw/~swanky/os/chap1.htm

    Interrupt, Exception, Trap and Interrupt Service Routines (ISR)

    紀錄一下連結 XD

    [SA] Hw1-1


    Requirements

    • Basic:
      • Install up-to-date –RELEASE of FreeBSD (9.1-R)
      • Add a user and a group
        • Group name should be identical to your username
        • User should also be in the ‘wheel’ group
      •  Set your machine to current time zone and adjust current time
      •  Enable sshd