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

目录
相关文章
|
23天前
|
存储 Unix 程序员
面试题:Ctrl + C在不同操作系统下的应用
字节跳动面试题:Ctrl + C在不同操作系统下的应用
38 1
|
8月前
|
Shell Linux 应用服务中间件
ABAP 面试题:如何使用 ABAP 编程语言的 System CALL 接口,直接执行 ABAP 服务器所在操作系统的 shell 命令?
ABAP 面试题:如何使用 ABAP 编程语言的 System CALL 接口,直接执行 ABAP 服务器所在操作系统的 shell 命令?
113 0
|
3月前
|
消息中间件 调度 C++
C/C++工程师面试题(操作系统篇)
C/C++工程师面试题(操作系统篇)
33 0
|
11月前
|
SQL 监控 安全
Linux操作系统面试题2
Linux操作系统面试题2
119 0
|
11月前
|
存储 安全 网络协议
Linux操作系统面试题1
Linux操作系统面试题
98 0
|
存储 缓存 监控
面试题(二十三)操作系统(一)
1.1 Linux里如何查看一个想知道的进程? 参考回答 查看进程运行状态的指令:ps命令。“ps -aux | grep PID”,用来查看某PID进程状态 答案解析 //ps使用示例 //显示当前所有进程 ps -A //与grep联用查找某进程 ps -aux | grep apache //查看进程运行状态、查看内存使用情况的指令均可使用top指令。 top 1.2 Linux里如何查看带有关键字的日志文件? 参考回答 1. cat 路径/文件名 | grep 关键词 # 返回test.log中包含http的所有行 cat test.log | grep "http"
94 0
|
消息中间件 存储 缓存
|
消息中间件 存储 机器学习/深度学习
常见面试题之操作系统
常见面试题之操作系统
120 0
|
存储 算法 Java
2.5w字 + 41 张图爆肝操作系统面试题(六)
大家好,我是 cxuan,我之前汇总了一下关于操作系统的面试题,最近又重新翻阅了一下发现不是很全,现在也到了面试季了,所以我又花了一周的时间修订整理了一下这份面试题,这份面试题可以吊打市面上所有的操作系统面试题了,不是我说,是因为我系统查过,如果有不相信的大佬,欢迎狠狠的打我脸。
2.5w字 + 41 张图爆肝操作系统面试题(六)
|
存储 缓存 算法
2.5w字 + 40 张图爆肝操作系统面试题(五)
大家好,我是 cxuan,我之前汇总了一下关于操作系统的面试题,最近又重新翻阅了一下发现不是很全,现在也到了面试季了,所以我又花了一周的时间修订整理了一下这份面试题,这份面试题可以吊打市面上所有的操作系统面试题了,不是我说,是因为我系统查过,如果有不相信的大佬,欢迎狠狠的打我脸。
2.5w字 + 40 张图爆肝操作系统面试题(五)