[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.

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

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

PCB of processes carries more state information than TCB of threads

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

Synchronization is more important in thread than process

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.

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

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

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?

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

Browser asks OS for server's IP address under that URL

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

Browser initiates a TCP connection with the server

Browser send a HTTP request to server

Server handle the incoming request

Browser receives the HTTP response and may close the TCP connection

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
01101=0×2
−1
+1×2
−2
+1×2
−3
+0×2
−4
+1×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)

目录
相关文章
|
6月前
|
存储 Unix 程序员
面试题:Ctrl + C在不同操作系统下的应用
字节跳动面试题:Ctrl + C在不同操作系统下的应用
123 1
|
存储 消息中间件 算法
操作系统常见面试题目总结,含答案
操作系统常见面试题目总结,含答案
|
5月前
|
存储 调度 C++
【操作系统】进程与线程的区别及总结(非常非常重要,面试必考题,其它文章可以不看,但这篇文章最后的总结你必须要看,满满的全是干货......)
【操作系统】进程与线程的区别及总结(非常非常重要,面试必考题,其它文章可以不看,但这篇文章最后的总结你必须要看,满满的全是干货......)
117 1
|
6月前
|
消息中间件 调度 C++
C/C++工程师面试题(操作系统篇)
C/C++工程师面试题(操作系统篇)
66 0
|
6月前
|
算法 安全 调度
[操作系统] 面试宝典之~死锁连环系列
[操作系统] 面试宝典之~死锁连环系列
|
6月前
|
存储 Linux 调度
[操作系统]秋招面试问到进程扩展知识!!!面试官喜欢的答案
[操作系统]秋招面试问到进程扩展知识!!!面试官喜欢的答案
|
存储 缓存 算法
操作系统笔记【面试】
操作系统笔记【面试】
82 1
|
存储 算法 Linux
操作系统面试高频考点
操作系统面试高频考点
|
SQL 监控 安全
Linux操作系统面试题2
Linux操作系统面试题2
142 0
|
存储 安全 网络协议
Linux操作系统面试题1
Linux操作系统面试题
126 0