Linux的开机启动顺序

对于x86机器的Linux的启动顺序,BIOS首先从启动设备载入MBR(Master Boot Record).存在MBR里的代码就去找分区表,从活动分区读入Linux的bootloader,最常用的像Grub,其它的有LILO,SYSLINUX。 Bootloader把压缩格式的内核映象载入并把控制权交给内核映像。 内核映像自解压,启动内核! x86处理器有两种工作模式。实模式和保护模式。在实模式,你只能够寻址1M内存。保护模式下,就复杂得多,可以作到使用处理器的很多高级特性比如分页。CPU必须从实模式转到保护模式是一个单行通道(one-way street)。你不能从保护模式退入实模式。 内核第一阶段的内核初始化是在实模式中完成的。接下来从init/main.c 中定义的 start_kernel()函数进入你保护模式。start_kernel()先初始化CPU subsystem。接下来启动存储器和进程管理。然后启动外围总线和IO设备。启动序列的最后一个阶段便是init进程被启动。这个进程是所有的Linux进程的祖先。Init进程执行用户空间的脚本。这些脚本被用来启动必要的内核服务程序。Init最后spawn一个控制台给你。于是启动就完成了。 copyright ykyi.net

November 25, 2011 · 1 min · kamus

ACM 马周游解题报告

<p> &nbsp; </p> <p> &nbsp; </p> <p> &nbsp; </p> <h3 style="text-align: left; "> <span style="font-size: 14px; ">简单的马周游问题</span> </h3> <p> &nbsp; </p> <p> &nbsp; </p> <p> </center> </div> <p> &nbsp; </p> <div> &nbsp; </div> <div> <span style="font-size:14px;">Description</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">在一个5 * 6的棋盘中的某个位置有一只马,如果它走29步正好经过除起点外的其他位置各一次,这样一种走法则称马的周游路线,试设计一个算法,从给定的起点出发,找出它的一条周游路线。</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">为了便于表示一个棋盘,我们按照从上到下,从左到右对棋盘的方格编号,如下所示:</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">1 &nbsp; &nbsp; 2 &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; 4 &nbsp; &nbsp; 5 &nbsp; &nbsp; 6</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">7 &nbsp; &nbsp; 8 &nbsp; &nbsp; 9 &nbsp; &nbsp; &nbsp; 10 &nbsp; &nbsp;11 &nbsp; &nbsp; &nbsp; 12</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">13 &nbsp; &nbsp;14 &nbsp; &nbsp; &nbsp; 15 &nbsp; &nbsp;16 &nbsp; &nbsp; &nbsp; 17 &nbsp; &nbsp;18</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">19 &nbsp; &nbsp;20 &nbsp; &nbsp; &nbsp; 21 &nbsp; &nbsp;22 &nbsp; &nbsp; &nbsp; 23 &nbsp; &nbsp;24</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">25 &nbsp; &nbsp;26 &nbsp; &nbsp; &nbsp; 27 &nbsp; &nbsp;28 &nbsp; &nbsp; &nbsp; 29 &nbsp; &nbsp;30</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">马的走法是&ldquo;日&rdquo;字形路线,例如当马在位置15的时候,它可以到达2、4、7、11、19、23、26和28。但是规定马是不能跳出棋盘外的,例如从位置1只能到达9和14。</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">Input</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">输入有若干行。每行一个整数N(1<=N<=30),表示马的起点。最后一行用-1表示结束,不用处理。</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">Output</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">对输入的每一个起点,求一条周游线路。对应地输出一行,有30个整数,从起点开始按顺序给出马每次经过的棋盘方格的编号。相邻的数字用一个空格分开。</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">Sample Input</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">4</span> </div> <div> <span style="font-size:14px;">-1</span> </div> <div> <span style="font-size:14px;">Sample Output</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">注意:如果起点和输入给定的不同,重复多次经过同一方格或者有的方格没有被经过,都会被认为是错误的。</span> </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">(1)原题中文大意</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">中国象棋的马按照象棋的规则在5 x 6 的棋盘上跑30步跑完所有的格子。</span> </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">(2)算法思想及解题用到的主要数据结构</span> </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">从每一个点往下走第二步,会有几点有效的行走位置。 把当前位置记在栈里面,以深度优先的方式进入下一个有效位置。如果下一个有效位置在之前已经走过,则从栈顶弹出上一位置,恢复到调出的位置后尝试未走过的有效位置。利用函数调用时会压栈的特别,用函数递归调用即可解决问题。</span> </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">(3)详细解题思路</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">1. 先初始化一张表。这张表记下了棋盘上所有的30个位置的下一步可走的有效位置.</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">2. 写一个一般的递归调用自己的函数,表示马在走第几步时到了哪个位置,然后尝试走余下的所有可走位置。</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">3. 递归函数有两个退出条件。要么下一个要尝试的点已经走过了,要么走到了最后一步,即得解!</span> </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">(4)逐步求精算法描述</span> </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">用一个数组记下来经过的点。</span> </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> &nbsp; </div> <div> <span style="font-size:14px;">(5)程序注释清单</span> </div> <div> &nbsp; </div> <div> <pre class="brush:cpp">#include &lt;iostream&gt; #include <cstring> #include <cstdlib> #include <vector> using namespace std; const static char row_num = 5; // 5行 const static char column_num = 6; // 6列 // 这个全局数组在初始化后会记下每30个有效位置的下一步可走位置. // elocution[x][0]记个数。最多8个有效可走位置。 char elocution[30][9]; struct coordinate // 坐标. { char _x; // start from zero. char _y; }; // 坐标转序号的函数。 char coordinate2serial_num(coordinate co) { char num = co._x * column_num + co._y + 1; return num; } // 序号转坐标的函数。 coordinate serial_num2coordinate(char sn) { coordinate co; co._x = (sn - 1) / column_num; co._y = sn - co._x * column_num - 1; return co; } // 增量数组. char increments[8][2] = { 1, -2, 2, -1, 2, 1, 1, 2, -1, 2, -2, 1, -2, -1, -1, -2 }; // 得用增量数组来计算每一个位置的下一步有效位置。记到steps里面. void next_step(char pos, char steps[]) { char valid_count = 0; coordinate co = serial_num2coordinate(pos); coordinate tmp; char serial_num; for ( int i = 0; i < 8; i++ ) { tmp._x = co._x + increments[i][0]; tmp._y = co._y + increments[i][1]; if ( tmp._x < 0 || tmp._x > 4 || tmp._y < 0 || tmp._y > 5 ) { continue; } serial_num = coordinate2serial_num(tmp); if ( serial_num >= 1 && serial_num <= 30 ) { valid_count++; steps[valid_count] = serial_num; } else { cerr << “Not expected to reach here.\n”; } } steps[0] = valid_count; } // 初始化记载所有点的下一步可走点的全局表。 void init_elocution() { for ( int i = 1; i <= 30; i++ ) { next_step(i, elocution[i-1]); } } char track[30]; // 记走过的路径. bool quit_run_horse; // 上文提高的递归函用函数. void run_horse(char start_pos, char step_count) { if ( quit_run_horse ) // 用来快速退出深嵌套递归调用函数. { return; } for ( int i = 0; i < step_count; i++ ) { // 已?经-经-过y这a点?了?. if ( track[i] == start_pos ) { return; } } track[step_count] = start_pos; // 记下新走过的位置 if ( step_count == 29 ) // 最后一步则打印出结果。 { for ( int i = 0; i < sizeof(track); i++ ) { cout << (int)track[i]; if ( i + 1 != sizeof(track) ) { cout << " “; } } cout << endl; quit_run_horse = true; return; } for ( int i = 0; i < elocution[start_pos-1][0]; i++ ) { run_horse(elocution[start_pos-1][i+1], step_count+1); } } int main(int argc, char* argv[]) { init_elocution(); int pos; vector<int> vec; while(true) { cin >> pos; if (pos==-1) { break; } vec.push_back(pos); } for ( int i = 0; i < vec.size(); i++ ) { quit_run_horse = false; run_horse(vec[i], 0); } return 0; }   ...

November 25, 2011 · 4 min · kamus

TIME is SO LIMITED

TIME is SO LIMITED I never imaged my graduate shcool life would be so busy. I ever though I would have enough time to read as many books in which I was interesting as I can. Actually there are a whopping pile of courses and homework to take. I seldom have enough time to read the books I’m planning to read. Time is so limitted, how I wish the lord would give me double the time, 24 hours a day. I would feel nervous and guilty when I was doing something which I deemed as a waste of time. I want to finish reading some books before the beginning of the following term. In order to achieve this goal I must manage my time much more efficient. As an example, time schedule every day should be more tight to reduce time fragment which are harder to use and much easiser to be wasted inadvertently. God, give me more time ! I’m so busy.

November 14, 2011 · 1 min · kamus

EMC易安信2011中山大学校园宣讲

今天听了EMC易安信的招聘宣讲会。EMC是这颗星球上最领先的海量存储设备供应商哇!~不久前并购了vmware。年收益近200亿美,大概比电信巨头华为少五六十亿美金。   可能宣传不力而且EMC的产品基本上面向企业级,不像其它巨头企业一样有吸引力,到场的人稀稀拉拉就二十几个。EMC高管就来了四个哇,而由大BOSS带队!!!中大的童鞋们太不给面子了~~   先是由EMC的老大讲了点公司的情况。这货94年tsinghua毕业,加州理工博士。哎哎哎哎。。哎哎哎~~~~ 然后由EMC的一个技术总监做presentation。相当明显的一儒雅型帅哥啊~~人才!人才啊!!! 同自己一比较…~~羡慕嫉妒恨!!!如果我这么优秀就好了。差太远了。上图.     最后环节,自由提问时。哥抢到了话筒。哥问大BOSS’EMC在上海,北京,成都都有研发。几时来华南设研发中心吖。’。结果令我相当地伤心啊,boss说两年内不会有这个打算。       拿Mic的是回答我提问的大BOSS哈。 另外。EMC每年20天带薪年假啊,不管新老员工。尼玛,20天带薪年假,我要疯掉啦!!!

October 13, 2011 · 1 min · kamus

knowledge gained from learning git.

# If you inadvertently remove a file of your working copy. Don’t worry. Git are good at recovering old versions of files, such as: $git checkout HEAD — data # show what the file looks like in a certain branch. $git show branch_name:file_name # In newer versions of Git, git diff –ours is a synonym for git diff HEAD, because it shows the differences between “our” version and the merged version. Similarly, git diff MERGE_HEAD can be written as git diff –theirs. You can use git diff –base to see the combined set of changes since the merge base, which would otherwise be rather awkwardly written as: git diff $(git merge-base HEAD MERGE_HEAD) ...

September 9, 2011 · 3 min · kamus

Diff, Patch, and Friends(diff, patch和他们的相关工具)(第二篇)

原文 http://www.linuxjournal.com/article/1237 翻译: www.ykyi.net zausiu 接上篇 Use the diff program to avoid eyestrain and insanity: 使用diff程序来避免会令人发疯的肉眼查找。 diff -u 1 2 — 1 Sat Apr 20 22:11:53 1996 +++ 2 Sat Apr 20 22:12:01 1996 -1,9 +1,9 Ecce Eduardus Ursus scalis nunc tump-tump-tump occipite gradus pulsante post Christophorum Robinum descendens. Est quod sciat unus et solus -modus gradibus desendendi, non nunquam autem +modus gradibus descendendi, nonnunquam autem sentit, etiam alterum modum exstare, dummodo -pulsationibus desinere et de no modo meditari +pulsationibus desinere et de eo modo meditari possit. Deinde censet alios modos non esse. En, nunc ipse in imo est, vobis ostentari paratus. Winnie ille Pu. ...

September 2, 2011 · 4 min · kamus

Syntax Highlight in DDD DDD的语法高亮

这几天用DDD调试linux下的程序.发现DDD没有语法高亮~ 于是google了一下。悲剧地发现一个贴子: Hello! Is it possible to enable syntax highlighting in DDD? I searched through the Google and found this answer: 可以在DDD里开启语法高亮吗?我用谷歌搜索后发现这个答案。 Sorry, no, this isn’t possible. The biggest problem is that Motif’s text widget doesn’t support multiple colours, and would have to be replaced. That would be an enormous job. 不好意思。没有!这不可能. 最大的问题是Motif的文本控件不支持多彩显示,必须把motif替换掉. 这不是一个普通的/简单的任务. ///////////////////// 悲剧啊!!!在黑白的Linux世界。……….. Is it still impossible (post date is Thu, 10 Feb 2005)? Are there any workarounds/patches/forks?

August 24, 2011 · 1 min · kamus

Diff, Patch, and Friends(diff, patch和他们的相关工具)(第一篇)

原文 http://www.linuxjournal.com/article/1237 翻译: ykyi.net “Kernel patches” may sound like magic, but the two tools used to create and apply patches are simple and easy to use—if they weren’t, some Linux developers would be too lazy to use them… “内核补丁"听起来相当之神奇,但是有两个用来创建补丁和应用补丁的工具却简单易用。如果它们很难用的话,一些Linux开发者才懒得用它们呢。 Diff is designed to show you the differences between files, line by line. It is fundamentally simple to use, but takes a little practice. Don’t let the length of this article scare you; you can get some use out of diff by reading only the first page or two. The rest of the article is for those who aren’t satisfied with very basic uses. diff这个工具设计成可以向你展示文件之间行与行的区别。它使用起来是相当的简单,但需要一点练习才习。你千万不要让长长的介绍文档把你吓住。你可以先只读前一两页文档,这样你就可以使用diff来开展一些工作了。余下的diff介绍文档是写给那些对基本用法非常不满的奇异人士的。 http://ykyi.net ...

February 12, 2011 · 3 min · kamus

摆明车马

#俗语 http://ykyi.net 广州话俗语.粤语俗语 摆明:清清楚楚地摆开,这里指明白讲清楚; 车马:象棋棋子。 意思是首先给给方明明白白讲清楚,以免日后误会发生争执。 %例句:我都摆明车马同佢讲楚个咯,费用由对方负责。点解仲要我哋出钱呀?(我都明明白白跟他们说清楚了,费用由对方负责。为什么还要我们出钱呀?)

January 2, 2011 · 1 min · kamus

白云山一担泥,眼阔肚窄

#歇后语 http://ykyi.net 广州话俗语.粤语俗语 白云山:位于广州市区北部,是个风景区; 从白云山挑一担泥下山,人们以为轻松便装得很满,谁知路远担重,往往无法完成。比喻人对东西总想多要,但实际上吃不了或用不了,无力消受。 %例句:你要得咁多,小心白云山一担泥,眼阔肚窄喔。(你要得那么多,小心消受不了啊。)

December 23, 2010 · 1 min · kamus