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

news/2025/6/2 7:01:11

操作系统

进程与线程

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 cache3 ns        Branch mispredict4 ns        L2 cache17 ns        Mutex lock/unlock100 ns        Main memory (RAM)2 000 ns (2µs)  1KB Zippy-compress16 000 ns (16µs) SSD random read500 000 ns (½ms)  Round trip in datacenter 
2 000 000 ns (2ms)  HDD random read (seek)
文章来源:https://blog.csdn.net/weixin_33810006/article/details/89463387
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:https://dhexx.cn/news/show-3424924.html

相关文章

Android-多线程Handler

http://www.cnblogs.com/plokmju/p/android_Handler.html android不允许在主线程里做耗时操作,如网络操作,以此来避免ANR ANR(Application Not Responding) http://baike.baidu.com/link?urlrLzKRNkjt79XITQKhRXp32alhsuKEt2FoHPw3vuB2UlEvyKOZwnEh4OYo…

黄聪:TinyMCE 4 增强 添加样式、按钮、字体、下拉菜单和弹出式窗口

我最喜欢 WordPress 3.9 的更新是使用了 TinyMCE 4.0 编辑器。新的 TinyMCE 看起来看起来更整洁(真正匹配WP仪表板),它有一些非常不错的附加功能。我的很多老主题和插件必须更新为新 TinyMCE 的工作,所以我花了一些时间研究 API 并…

D. Easy Problem(简单DP)

题目链接:http://codeforces.com/contest/1096/problem/D 题目大意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在hard这个单词,可以是不连续的。 具体思路:我们从头开始&…

Windows Azure 内部IP

#查看订阅#Get-AzureSubscription#选择订阅#Select-AzureSubscriptionc -SubscriptionId 7a16c12-44da-4820-2233-61e142181118#查看VNET配置#Get-AzureVNetSite#测试IP地址是否被占用#PS C:\> Test-AzureStaticVNetIP -VNetNametempsun -IPAddress 10.0.0.5详细信息: 10:4…

单调栈(G - Sliding Window POJ - 2823 )

题目链接:https://cn.vjudge.net/contest/276251#problem/G 题目大意:给你n和m,然后问你对于(m,n)这中间的每一个数,(i-m1,i)这个区间的最小值和最大值。 具体…

Linux-压缩与解压缩命令

常用的压缩格式:.zip .gz .bz2 .tar.gz .tar.bz2 1.Zip 压缩文件:zip 压缩文件名 源文件 压缩目录:zip -r 压缩文件名 源文件 解压缩.zip文件:unzip 压缩文件 2.gz gzip 源文件:压缩为.gz格式的压缩文件&…

OK335xS CAN device register and deiver match hacking

/************************************************************************** OK335xS CAN device register and deiver match hacking* 声明:* 本文主要是跟踪CAN设备的注册、和驱动的匹配方式,了解CAN的注册流程。** …

字符串hash对字符串hash的理解

对字符串hash的一些总结: 1,首先,我们在转化的时候,取底的时候一般是取131这些数,因为要避免不同的字符串对应相同的hash值这种情况的出现。如果卡精度的时候,我们可以采取双模数的方式尽量减少误差&#…

C++ STL标准模板库(queue)

//queue的使用 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<queue> using namespace std;/* 引用头文件 #include<queue>queue类本身是一个类模板C队列是一种容器适配器&#xff0c;它给予程序员一种先进先出(FIFO)的数据结构。 1.back(…

状压dp(B - 炮兵阵地 POJ - 1185 )

题目链接&#xff1a;https://cn.vjudge.net/contest/276236#problem/B 题目大意&#xff1a;略 具体思路&#xff1a;和我的上一篇写状压dp的思路差不多&#xff0c;不过就是这个题相当于上一个题的升级版&#xff0c;变成了左右&#xff0c;上下都会有限制&#xff0c;并且限…