Linux内核如何装载和启动一个可执行程序
摘要:###exec本节我们分析exec系统调用的执行过程。 exec一般和fork调用,常规用法是fork出一个子进程,然后在子进程中执行exec,替换为新的代码。###do_exec跟上次的fork类似,这里我们查看do_exec函数。```cint do_execve(struct filenam...
阅读全文
posted @
2015-04-19 12:46
inevermore
阅读(1822)
推荐(0)
分析Linux内核创建一个新进程的过程
摘要:###进程创建Linux中创建进程一共有三个函数: 1. fork,创建子进程 2. vfork,与fork类似,但是父子进程共享地址空间,而且子进程先于父进程运行。 3. clone,主要用于创建线程这里值得注意的是,Linux中得线程是通过模拟进程实现的,较新的内核使用的线程库一般都是NPTL。...
阅读全文
posted @
2015-04-12 21:34
inevermore
阅读(1169)
推荐(0)
分析system_call中断处理过程
摘要:#分析system_call中断处理过程上周我们使用gcc内嵌汇编调用系统调用,这次我们具体分析下过程。###将getpid嵌入menuos代码从github下载,步骤如下: 1. 增加一个函数,getpid 2. 在main中添加MenuConfig("getpid","Show Pid", G...
阅读全文
posted @
2015-04-05 22:26
inevermore
阅读(479)
推荐(0)
通过swap代码分析C语言指针在汇编级别的实现
摘要:我们先用C语言写一个交换两个数的代码:```Cvoid swap(int *a, int *b){ int temp = *a; *a = *b; *b = temp;}int main(void){ int x = 12; int y = 34; swap(&a...
阅读全文
posted @
2015-04-04 23:02
inevermore
阅读(1690)
推荐(0)
使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用
摘要:本周作业的主要内容就是采用gcc嵌入汇编的方式调用system call。 系统调用其实就是操作系统提供的服务。我们平时编写的程序,如果仅仅是数值计算,那么所有的过程都是在用户态完成的,但是我们想将变量打印在屏幕上,就必须调用printf,而printf这个函数内部就使用了write这个系统调用。...
阅读全文
posted @
2015-03-28 16:29
inevermore
阅读(854)
推荐(0)
Linux内核启动分析过程-《Linux内核分析》week3作业
摘要:环境搭建环境的搭建参考课件,主要就是编译内核源码和生成镜像start_kernel从start_kernel开始,才真正进入了Linux内核的启动过程。我们可以把start_kernel看做平时用C编程时的main函数。在平时应用程序编程中,main函数并不是一开始就启动的,而是先使用汇编和C准备一...
阅读全文
posted @
2015-03-22 17:04
inevermore
阅读(950)
推荐(0)
分析Linux内核中进程的调度(时间片轮转)-《Linux内核分析》Week2作业
摘要:###1.环境的搭建:这个可以参考孟宁老师的github:[mykernel](https://github.com/mengning/mykernel),这里不再进行赘述。主要是就是下载Linux3.9的代码,然后安装孟宁老师编写的patch,最后进行编译。###2.代码的解读课上的代码全部保存在...
阅读全文
posted @
2015-03-14 18:19
inevermore
阅读(1805)
推荐(0)
分析一个C语言程序生成的汇编代码-《Linux内核分析》Week1作业
摘要:###署名信息 郭春阳 原创作品转载请注明出处 :《Linux内核分析》MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 ###C源码这里为了防止重复,修改了部分源码```Cint g(int x){ return x + 99;}in...
阅读全文
posted @
2015-03-08 00:04
inevermore
阅读(354)
推荐(0)
探究加法操作的原子性
摘要:加法在多线程下是否可靠? 我们先看下面的实例: #include #include #include #include #include #include using namespace std; int g_count = 0; int main(int argc, const char *argv[])
{ vector> ths; for ...
阅读全文
posted @
2015-02-09 21:41
inevermore
阅读(1108)
推荐(0)
Ubuntu14.04使用samba服务器共享Home目录
摘要:这里记录一下,以Ubuntu 14.04为例。 1.安装samba服务器。 sudo apt-get install samba 2.修改配置文件 sudo vim /etc/samba/smb.conf 然后找到home目录共享的部分,大概是190-214行,将前面的注释去掉,如下: # Un-comment the following (and twea...
阅读全文
posted @
2015-01-03 18:43
inevermore
阅读(2563)
推荐(0)
getopt函数的用法
摘要:Linux提供了一个解析命令行参数的函数。 #include int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; ...
阅读全文
posted @
2014-11-25 21:31
inevermore
阅读(419)
推荐(0)