Giter Club home page Giter Club logo

os_and_network_programming's Introduction

OS跟網路程式筆記

  • simple shell
    • demo pic
    • 以C實作的簡易shell,支援一般指令、背景執行(&)、multiple pipeline。
    • 以double fork防止zombie process(主要用於背景執行)。
    • 以recursive實現multiple pipeline的fd處理。
    • 不支援cd、redirect dataflow等操作。
  • chatroom
    • demo pic
    • 用pthread跟socket實現的多人線上聊天室,但礙於那時對socket了解有限,部分架構不夠優美。
    • 後續分別在BBS、BBS with single thread上用pthread、select實現了不同用戶對話的server-client model。
  • matrix production
    • demo pic
    • 分別用multithread跟multiprocess實現平行化的矩陣乘法,目的在於直觀感受平行化的加速。
    • 由於使用機器cpu有限,超過8個thread/process後沒有顯著改善。
    • thread的表現略優於process,猜測是process switch成本更高的原因。
  • BBS

    感謝Jason提醒多線程中,strtok有共用記憶體的問題,改用strtok_r實現

    • demo pic
    • 以OOP、multithread、mutex的概念實作BBS。
    • 為了在多人交互時,不同時修改同一個記憶體導致資料損毀,使用排他鎖及讀寫鎖維護。
    • server端操作:
      • 編譯指令:g++ *.cpp
      • ./a.out <IP> <port> <max user>
      • IP僅能使用本機上網卡的IP,或以0.0.0.0代表本地IP
      • Port須大於1024(1024前為通用port)
      • max user不為負數
    • client端操作:
      • nc <IP> <port>:連線server
      • register <username> <password>:註冊用戶
      • login <username> <password>:登入用戶
      • whoami:查詢當前帳號名稱
      • list-user:列出所有用戶
      • send <username> <message>:給指定用戶訊息
      • list-msg:分別列出從各用戶收到的信息數量
      • receive <username>:列出從用戶收到的所有訊息
      • logout:登出
      • exit:中斷連線
  • BBS with single thread
    • demo pic
    • 與BBS功能類似,但實做方式不同,使用select在單一thread上handle多個socket(file descipter)的交互,使程式更加scalable,但與此同時,使用論詢的select在效率上較差(可以用epoll改善)。
    • Makefile
      • make:編譯server、client執行檔
      • make clean:刪除server、client執行檔
    • server端操作:
      • ./server <port>
    • client端操作:
      • ./client <IP> <port>:連線到server
      • name <username>:重新命名user,默認為匿名使用者(anonymous)
      • who:查看在線使用者,以及各使用者的IP、port跟名稱
      • tell <username> <message>:私訊另一名使用者,匿名使用者無權限發送、接收私訊
      • yell <message>:廣播訊息,匿名使用者無權限發送廣播
      • exit:離開server

os_and_network_programming's People

Contributors

1am9trash avatar

Stargazers

Chieh Nien avatar Chia-Lun Tsai avatar Patrick Star avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.