[CS101] Operating System and Low Level Fundamental 操作系统及底层基础面试题

操作系统

进程与线程

What’s the difference between thread and process?
A process is an instance of a computer program that is being executed. It contains the program code and its current activity. A process may be made up of multiple threads.

  1. Process are typically independent, while threads exist as as subsets of a process.

  2. Process has much more overhead than thread due to slower context switch

  3. PCB of processes carries more state information than TCB of threads

  4. All threads of a process share its virtual address space and system resources.

  5. Synchronization is more important in thread than process

  6. Processes interact only through system-provided inter-process communication mechanisms

How do processes communicate?
Cooperating processes require an inter process communication (IPC) mechanism that will allow them to exchange data and information.

  1. Shared memory
    A shared memory region resides in the address space of the process creating the shared memory segment. Other processes that wish to communicate using this shared memory segment must attach it to their address space.
    Examples: POSIX Shared memory

  2. Message passing
    It is particularly useful in a distributed environment. If process P and Q want to communicate, they must send message to and receive messages from each other. A communication link must exist between them.
    Examples: Mailboxes, ports, local/remote procedure call

  3. File
    Communicating with files is the most basic way to do inter-process communication.

How do threads communicate?
At the lowest level, threads communicate with each other by writing to the same memory location. To ensure that multiple threads do not write simultaneously at this memory location (causing race condition), various synchronization mechanism are used to enforce mutual exclusion such that allowing only one thread to access the data at a time.

网络

What is latency? What is throughput?
Latency is the time required to perform some action or to produce some result.Latency is measured in units of time — hours, minutes, seconds, nanoseconds or clock periods.
Throughput is the number of such actions executed or results produced per unit of time. This is measured in units of whatever is being produced (cars, motorcycles, I/O samples, memory words, iterations) per unit of time. The term “memory bandwidth” is sometimes used to specify the throughput of memory systems.

What happens when you type in a URL in browser?

  1. Browser checks cache first, if requested object is in cache and is fresh, jump to 8

  2. Browser asks OS for server’s IP address under that URL

  3. OS makes a DNS lookup and replies the IP address to the browser

  4. Browser initiates a TCP connection with the server

  5. Browser send a HTTP request to server

  6. Server handle the incoming request

  7. Browser receives the HTTP response and may close the TCP connection

  8. Browser determines what to do with response, cache, decode or render

分布式计算

What is the difference between Git and SVN?

  • GIT is distributed, SVN is not.

  • GIT stores content as metadata, SVN stores just files

  • GIT branches are not the same as SVN branches. Branches in SVN are nothing but just another Folder in the repository

  • GIT does not have a global revision no. like SVN do

  • GIT’s content integrity is better than SVN’s

计算机组织结构

存储器

What are big endian and little endian? How to tell whether a computer is big or little endian?
The decimal number 1025:

00000000 00000000 00000100 00000001

In memory, it is:

Address    Big-Endian      Little-Endian
00         00000000        00000001
01         00000000        00000100
10         00000100        00000000
11         00000001        00000000

We can tell it by checking the content in specific address:

int main()
{
    int x = 1;
    char *y = (char*)&x;
    printf("%c\n",*y+48);
}

If it prints 1, then it is little endian. If it prints 0, then it is big endian. Because char will only occupy first byte.

How to represent a float in memory?

There’re three sections while representing the float number: 1bit Sign Bit, 8bit Exponent and 23bit Significand

+-+--------+-----------------------+
| |        |                       |
+-+--------+-----------------------+
 0 10000100 11001001000011111100111
 ^     ^               ^
 |     |               |
 |     |               +--- significand = 0.7853975
 |     |
 |     +------------------- exponent = 4
 |
 +------------------------- sign = 0 (positive)

Sign bit: 0 indicates positive, 1 indicates negative
Exponent: Range of exponent is from -128 to 127. To be specific, 10000000 represents 0, 00000000 represents -128, 11111111 represents 127
Significand: Each bit represents a negative power of 2 counting from the left, if the significand is 01101, then the value should be:

$$ 01101=0\times 2^{-1}+1\times 2^{-2}+1\times 2^{-3}+0\times 2^{-4}+1\times 2^{-5} = 0.25+0.125+0.03125 = 0.40625 $$

What’s the approximate time cost to access various storage?

        1 ns        L1 cache
        3 ns        Branch mispredict
        4 ns        L2 cache
       17 ns        Mutex lock/unlock
      100 ns        Main memory (RAM)
    2 000 ns (2µs)  1KB Zippy-compress
   16 000 ns (16µs) SSD random read
  500 000 ns (½ms)  Round trip in datacenter 
2 000 000 ns (2ms)  HDD random read (seek)
    原文作者:ethannnli
    原文地址: https://segmentfault.com/a/1190000003710258
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞