Skip to content

Instantly share code, notes, and snippets.

@YZLRYO
Last active February 20, 2018 21:47
Show Gist options
  • Save YZLRYO/ff85c48d38a7dc8f2c5c0c57418867da to your computer and use it in GitHub Desktop.
Save YZLRYO/ff85c48d38a7dc8f2c5c0c57418867da to your computer and use it in GitHub Desktop.
Interview pre
what happens in the kernel when you execute "curl http://facebook.com",
Executable and Linking Format
你需要知道的是所谓对象文件(Object files)有三个种类:
1) 可重定位的对象文件(Relocatable file)
这是由汇编器汇编生成的 .o 文件。后面的链接器(link editor)拿一个或一些 Relocatable object files 作为输入,经链接处理后,生成一个可执行的对象文件 (Executable file) 或者一个可被 共享的对象文件(Shared object file)。我们可以使用 ar 工具将众多的 .o Relocatable object files 归档(archive)成 .a 静态库文件。如何产生 Relocatable file,你应该很熟悉了,请参见 我们相关的基本概念文章和JulWiki。另外,可以预先告诉大家的是我们的内核可加载模块 .ko 文件也是 Relocatable object file。
2) 可执行的对象文件(Executable file)
这我们见的多了。文本编辑器vi、调式用的工具gdb、播放mp3歌曲的软件mplayer等等都是Executable object file。你应该已经知道,在我们的 Linux 系统里面,存在两种可执行的东西。除了这里 说的 Executable object file,另外一种就是可执行的脚本(如shell脚本)。注意这些脚本不是 Executable object file,它们只是文本文件,但是执行这些脚本所用的解释器就是 Executable object file,比如 bash shell 程序。
3) 可被共享的对象文件(Shared object file)
这些就是所谓的动态库文件,也即 .so 文件。如果拿前面的静态库来生成可执行程序,那每个生成的可执行程序中都会有一份库代码的拷贝。如果在磁盘中存储这些可执行程序,那就会占用额外的 磁盘空间;另外如果拿它们放到Linux系统上一起运行,也会浪费掉宝贵的物理内存。如果将静态库换成动态库,那么这些问题都不会出现。动态库在发挥作用的过程中,必须经过两个步骤:
a) 链接编辑器(link editor)拿它和其他Relocatable object file以及其他shared object file作为输入,经链接处理后,生存另外的 shared object file 或者 executable file。
b) 在运行时,动态链接器(dynamic linker)拿它和一个Executable file以及另外一些 Shared object file 来一起处理,在Linux系统里面创建一个进程映像。
1) .text section 里装载了可执行代码;
2) .data section 里面装载了被初始化的数据;
3) .bss section 里面装载了未被初始化的数据;
4) 以 .rec 打头的 sections 里面装载了重定位条目;
5) .symtab 或者 .dynsym section 里面装载了符号信息;
6) .strtab 或者 .dynstr section 里面装载了字符串信息;
7) 其他还有为满足不同目的所设置的section
Questions:
I previously work with containers during my last internship in Intel, I am interested applying Virtualization tech.
Applying Virtualization to server clouds to make full use of hardware resources. AWS using Xen-based hypervisor, google using containers and Kubernetes to manage them.
I learned that from the previous interviewer that Facebook is also currently using containers for your services.
As long as I know, containers are vulnerable to security problems.
I previously met problems that users could even shut the physical machine off,
( If the container shares the net namespace with the host it is allowed to sent messages to init, so nothing prohibits it from changing the runlevel or shutting down the machine.)
what kind of security problems will you meet and how do you deal with them?
经典题,当输入ls -al *.c的时候发生什么
1) fork ()
2) connect pipes
3) look up the command
4) do redirections ?
5) execve ()
6) If the execve failed, see if the file has executable mode set. ?
Redundant Array of Independent Disks:
is a data storage virtualization technology that combines multiple physical disk drive components into one or more logical units for the purposes of data redundancy, performance improvement, or both.
RAID 0: striping(一段data存在不同devices上), no pairing and mirroring
The capacity of a RAID 0 volume is the sum of the capacities of the disks in the set, the same as with a spanned volume, no added redundancy for handling disk failures
pro: concurrent I/O provides higher I/O, con: extra vulnerbility
RAID 1: data mirroring, without parity or striping
RAID 2: consists of bit-level striping with dedicated Hamming-code parity
RAID 3: consists of byte-level striping with dedicated parity.
RAID 4 consists of block-level striping with dedicated parity.
RAID 5 consists of block-level striping with distributed parity.
什么是swap memory
先是swap机制 什么时候用 好坏 怎么判断谁被swap走 linux做swap整个流程是什么样的里面各种判定细节 本来准备到了这道题 但是问的太细 还是有些答不出
·A buffer is something that has yet to be "written" to disk.
·A cache is something that has been "read" from the disk and stored for later use
·https://www.cnblogs.com/coldplayerest/archive/2010/02/20/1669949.html
·free http://man.linuxde.net/free
· swap概念: http://blog.sina.com.cn/s/blog_502d765f0100krph.html
· swap配置: swapness概念 https://en.wikipedia.org/wiki/Swappiness, temp:
4G以内的物理内存,SWAP 设置为内存的2倍。
4-8G的物理内存,SWAP 等于内存大小。
8-64G 的物理内存,SWAP 设置为8G。
64-256G物理内存,SWAP 设置为16G。
· swap文件位置查看 :swapon -s ,http://blog.csdn.net/x_r_su/article/details/52957559
++++ 重要: https://segmentfault.com/a/1190000008125116
为什么需要swap?
要回答这个问题,就需要回答swap给我们带来了哪些好处。
1. 有了swap后,系统就可以将部分不这么使用的内存数据保存到swap上去,从而释放出更多的物理内存供系统使用。
2. 当系统休眠的时候,会将内存中的数据保存到swap分区上,等下次系统启动的时候,再将数据加载到内存中,这样可以加快系统的启动速度,所以如果要使用休眠的功能,必须要配置swap分区,并且大小一定要大于等于物理内存
3 总有一些意想不到的状况,比如某个进程需要的内存超过了预期,或者有进程存在内存泄漏等,当内存不够的时候,就会触发内核的OOM killer,根据OOM killer的配置,某些进程会被kill掉或者系统直接重启(默认情况是优先kill耗内存最多的那个进程),不过有了swap后,可以拿swap当内存用,虽然速度慢了点,但至少给了我们一个去debug、kill进程或者保存当前工作进度的机会。
如果看过Linux内存管理,就会知道系统会尽可能多的将空闲内存用于cache,以加快系统的I/O速度,所以如果能将不怎么常用的内存数据移动到swap上,就会有更多的物理内存用于cache,从而提高系统整体性能。
swap的缺点?
1. swap是存放在磁盘上的,磁盘的速度和内存比较起来慢了好几个数量级,如果不停的读写swap,那么对系统的性能肯定有影响,尤其是当系统内存很吃紧的时候,读写swap空间发生的频率会很高,导致系统运行很慢。
2. 由于系统会自动将不常用的内存数据移到swap上,对桌面程序来说,有可能会导致最小化一个程序后,再打开时小卡一下,因为需要将swap上的数据重新加载到内存中来。
什么是system call
system call is API kernel space provides to userspace when user wants to do something requires privilige to do.
This interface is needed because there are things (eg: I/O instructions) that only the kernel is allowed to perform。
„ File manipulations:
– open,close,creat,rename
– read, write, lseek
„ Directory manipulations:
– chdir, mkdir
– link, unlink
„ stdin, stdout, stderr
Processes:
– getpid,execl,fork
Other:
– time
when you execute "telnet google.com 80", what happend?
find command telnet in path
fork a process to execve /path/telnet, google, 80
1. check local host, if find go to the IP, if not next
2. check DNS (Domain Name System) for the domain,if so go to, no check root DNS
3. make connection, building Socket in first two, SYNC, SYNC-ACK, ACK with HTTP, 客户机和服务器都创建了一个由源IP地址、源端口号、目的IP地址和目的端口号标志的Socket。
4. ip level, hop-to-hop, check route table for destination to hop to the nect
5. connection established, do things
7. close connection, client -> FIN, server -> ACK, server -> FIN, client ->ACK, wait close connection
Network Model
4 application layer 例如HTTP、FTP、DNS
3 transport layer 例如TCP、UDP、RTP、SCTP
2 internet layer 对于TCP/IP来说这是因特网协议(IP)
1 link layer 例如以太网、Wi-Fi、MPLS等。
1. recognize and parse URL, protocol, domain, path, port
2. check local host, if find go to the IP, if not next
3. check DNS (Domain Name System) for the domain,if so go to, no check root DNS
4. 封装HTTP请求
5. make connection, building Socket in first two, SYNC, SYNC-ACK, ACK with HTTP, 客户机和服务器都创建了一个由源IP地址、源端口号、目的IP地址和目的端口号标志的Socket。
6. ip level, hop-to-hop, check
7. close connection, client -> FIN, server -> ACK, server -> FIN, client ->ACK, wait close connection
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 21688 12797396 850716 15372668 0 0 3 35 0 0 1 0 99 0 0
*** http://nonfunctionaltestingtools.blogspot.com/2013/03/vmstat-output-explained.html
Under Procs we have
r: The number of processes waiting for run time or placed in run queue or are already executing (running)
b: The number of processes in uninterruptible sleep. (b=blocked queue, waiting for resource (e.g. filesystem I/O blocked, inode lock))
: “cat /proc/cpuinfo” dispalys the cpu info on the machine
Under Memory
swpd: shows how many blocks are swapped out to disk (paged). The amount of Virtual memory used.
Note: you can see the swap area configured in server using "cat proc/swaps"
>cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-7 partition 16777208 21688 -1
free: The amount of Idle Memory
buff: Memory used as buffers, like before/after I/O operations
cache: Memory used as cache by the Operating System
Under Swap we have:
si: Amount of memory swapped in from disk (/s). This shows page-ins
so: Amount of memory swapped to disk (/s). This shows page-outs. The so column is zero consistently, indicating there are no page-outs.
Under IO we have:
bi: Blocks received from block device - Read (like a hard disk)
bo: Blocks sent to a block device – Write
Under System we have:
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
(A context switch occurs when the currently running thread is different from the previously running thread, so it is taken off of the CPU.)
Under CPU we have:
These are percentages of total CPU time.
us: % of CPU time spent in user mode (not using kernel code, not able to acces to kernel resources). Time spent running non-kernel code. (user time, including nice time)
sy: % of CPU time spent running kernel code. (system time)
id: % of CPU idle time
wa: % of CPU time spent waiting for IO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment