方宏育
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    JJ/Homework1(面試題目) === # 1. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` Semaphore 和 Mutex 的差異 ``` 解答: ``` counter vs. owner priority inversion Semaphore與mutex都是在處理同步問題的機制,最主要的差別是: semaphore是一個counter的概念,可以設定有多少個process存取資源,如果存取的process數量到達上限,其他要求存取資源的process會被送到wait queue中,等待有process釋放資源,再繼續執行。 Mutex就像是一把鑰匙,會記錄擁有這把鑰匙的owner是哪個process,process需要取得鑰匙後才能進到critical section存取資源,等到存取完成後才釋放出這把鑰匙的擁有權,達到mutual exclusion。 mutex還需要注意另一個priority inversion問題,假設A,B,C 三個process 優先權 A>B>C C握有lock,A在等lock造成優先權高的A等待C的情況,若此時B變為可執行的,則B會preempt process C,造成process A需要等待更久的時間,這種情況稱為unbounded priority inversion。 發生這種情況是用priority inheritance protocol來解決,即暫時提高C的priority繼承A的priority,這樣就能阻止process B preempt,等C執行完時再放棄繼承priority,回復原本的priority。 ``` 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 2. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` Process 和 Thread 的差異 ``` 解答: ``` address space process:將程式(program)載入記憶體中,變成可執行的process。 thread:一個process可以產生多個thread。 process 之間的address space並不相同,thread則共用相同的address space。 linux threading model (3) Red-black tree 在 Linux 核心的應用 ``` ![](http://www.tutorialspoint.com/operating_system/images/thread_processes.jpg) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 3. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` 用 C 語言實做 big-endian 和 little-endian 互轉的程式 ``` 解答:以 uint32_t 為例 ```C++= unsigned uint32_t swap_uint32( uint32_t val ) { val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF ); return (val << 16) | (val >> 16); } int32_t swap_int32( int32_t val ) { val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF ); return (val << 16) | ((val >> 16) & 0xFFFF); } ``` [參考]( http://www.prudentman.idv.tw/2007/11/big-enttradianlittle-endian.html) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 4. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` C++ function overriding vs. overloading ``` 解答 - Overloading:是一個簡化函式命名的技巧,有多個相同名稱的函式,依據傳入的parameter list數量或是型別的不同,決定該呼叫哪一個函式。如: ```C++= void print(int i) {...} void print(double d) {...} void print (char c) {...} ``` - Overriding:子類別將父類別函式重新定義成符合自身所需,使得相同的函式在不同的類別,會有不同的行為反應。如: ```C++= class person { public void iam() { cout<<"i am person"; } } class superman extends person { public void iam() { cout<< "i am superman"; } } ``` [參考網站](http://antrash.pixnet.net/blog/post/79139547-%E8%AB%96%E7%89%A9%E4%BB%B6%E5%B0%8E%E5%90%91part-8%EF%BC%9Awhy-overloading%E3%80%81overriding) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 5. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` C++的copy constructor, deep copy ``` 解答: **constructor的功用是讓我們在建立物件的同時,就初始化資料成員的內容,constructor必須與類別同名,並且不能有回傳值,若無定義constructor,編譯器會替類別定義一個default constructor** <br> - copy constructor:當程式定義新物件,並且以同類別其他物件來做初始值時會呼叫copy constructor,來進行物件複製 ```C++= class time{ public: time(int); private: int hour; }; time::time(int h){ //constructor hour = h; } time::time(const time &t){ //copy constructor hour = t.hour; } int main(){ time t1(9); time t2 = t1; //t2,t3,t4都會呼叫copy constructor time t3(t2); time t4 = time(t3); } ``` - deep copy:會再開闢一個記憶體區塊複製一份指標所指向的變數內容給指定的物件,因此被複製的物件及指定的物件所存取的變數就不會互相影響 ```C++= class MyString { private: char *m_pchString; int m_nLength; public: MyString(char *pchString="") { // Find the length of the string // Plus one character for a terminator m_nLength = strlen(pchString) + 1; // Allocate a buffer equal to this length m_pchString= new char[m_nLength]; // Copy the parameter into our internal buffer strncpy(m_pchString, pchString, m_nLength); // Make sure the string is terminated m_pchString[m_nLength-1] = '\0'; } MyString::MyString(const MyString& cSource) { // because m_nLength is not a pointer, we can shallow copy it m_nLength = cSource.m_nLength; // m_pchString is a pointer, so we need to deep copy it if it is non-null if (cSource.m_pchString) { // allocate memory for our copy m_pchString = new char[m_nLength]; // Copy the string into our newly allocated memory strncpy(m_pchString, cSource.m_pchString, m_nLength); } else m_pchString = 0; } ~MyString() // destructor { // We need to deallocate our buffer delete[] m_pchString; // Set m_pchString to null just in case m_pchString = 0; } char* GetString() { return m_pchString; } int GetLength() { return m_nLength; } }; ``` [參考網站](http://www.learncpp.com/cpp-tutorial/915-shallow-vs-deep-copying/) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 6. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` 簡述 TLB(translation look-aside buffer,TLB) ``` 解答: ``` 到main memory中查詢page table是很耗時的工作, 因此將最近常用到的分頁目錄及entry存到TLB cache中,用來加速對physical memory的存取。 若要找的頁數不在TLB中,則發生TLB miss,必須到main memory找分頁項目, 再對physical memory進行存取,並且將頁數和欄號加到TLB中,若TLB已經滿了, 則移除最近最少使用的項目(LRU) ``` ![](https://hackpad-attachments.imgix.net/hackpad.com_5TOjUJI2rKu_p.126342_1412615169290_images.jpg?fit=max&w=882) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 7. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` page fault 與 OS kernel 對應的行為 ``` 解答: ``` page fault: main memory中找不到資料而需要到second memory中找,稱作page fault ``` 步驟: ![](http://www.cs.odu.edu/~cs471w/spring10/lectures/virtualmemory_files/image008.jpg) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 8. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` cache invalidate, cache flush 發生的時機 ``` 解答: [reference link](https://hackpad.com/2014914-M4UmNprwldI#:h=(5)-DMA-和-cache-的關聯) 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- # 9. 公司名稱:模擬面試 職務說明:NA 面試題目: ``` 給定 opendir() 與 readdir() 函式,用遞迴寫出類似 find 的程式page fault 與 OS kernel 對應的行為 ``` 解答: ***find 的功能:列出包含目前目錄和其所有子目錄之下的檔案名稱*** ```C= void list_dir (const char *dir_name) { DIR * d = opendir (dir_name); if (! d) { fprintf (stderr, "Cannot open directory '%s\n", dir_name); return; } while (1) { const char * d_name; struct dirent * entry = readdir (d); if (! entry) break; ``` ```C= d_name = entry->d_name; printf ("%s/%s\n", dir_name, d_name); if (entry->d_type & DT_DIR) { if (strcmp (d_name, "..") != 0 && strcmp (d_name, ".") != 0) { int path_length; char path[PATH_MAX]; path_length = snprintf (path, PATH_MAX, "%s/%s", dir_name, d_name); printf ("%s\n", path); if (path_length >= PATH_MAX) { fprintf (stderr, "Path length has got too long.\n"); return; } /* Recursively call "list_dir" with the new path. */ list_dir (path); } } } if (closedir (d)) { fprintf (stderr, "Could not close '%s'\n", dir_name); return; } } ``` 流程:NA 出處:[資訊科技產業面試模擬和工作咨詢 (2014/10/5)](https://hackpad.com/-2014105-5TOjUJI2rKu) --- [資訊科技產業面試模擬和工作咨詢](http://wiki.csie.ncku.edu.tw/embedded/rehearsal)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully