This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 在linux内核源码中,文件include/linux/sched.h说: | |
| /** | |
| * cloning flags: | |
| */ | |
| #define CSIGNAL 0x000000ff /** signal mask to be sent at exit */ | |
| #define CLONE_VM 0x00000100 /** set if VM shared between processes */ | |
| #define CLONE_FS 0x00000200 /** set if fs info shared between processes */ | |
| #define CLONE_FILES 0x00000400 /** set if open files shared between processes */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 问题: | |
| 在启动引导试,linux映像是怎么从外存被载入内存的? | |
| 细细思考,这里面涉及一些小问题。就目前理解解答如下: | |
| 0,当没有驱动时,BIOS用于读外存/外设; | |
| 1,从BIOS到引导程序,引导程序在一个固定位置,所以BIOS能找到并加载其到内存中执行; | |
| 2,同样的,内核映像也必须在一个引导程序知道的位置处,引导程序将其从外存加载到内存; | |
| 3,不使用文件系统的bootsect.s,直接CALL BIOS来加载紧随其后的setup,及紧随setup之后的vmlinux; | |
| 4,试用文件系统的其他引导程序,通过其文件系统的vmlinux文件位置,将vmlinux从外存载入内存。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 数组的相邻数据间的差的绝对值为1,找出某个值t在数组中的出现位置 | |
| // 本方法找出t在数组中的第一次出现 | |
| #include <cstdlib> | |
| #include <iostream> | |
| using std::cout; | |
| using std::endl; | |
| const int NUM = 20; | |
| int data[NUM]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdlib> | |
| #include <iostream> | |
| using std::cout; | |
| using std::endl; | |
| const int NUM = 4; | |
| int data[NUM]; | |
| void init(int data[], int n) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdlib> | |
| #include <iostream> | |
| using std::swap; | |
| using std::cout; | |
| using std::endl; | |
| template <typename T> | |
| void print(T a[], int n) { | |
| for (int i = 0; i <= n-2; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // use c to simulate the mechanism of virtual function in c++. | |
| // designed by [email protected] | |
| #include <iostream> | |
| using std::cout; | |
| using std::endl; | |
| // C: function pointer | |
| void fun1() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1, 进程上下文和中断上下文在Linux内核中的区别 | |
| process context: 运行中的程序从用户空间进入内核空间,此时内核处于进程上下文并为进程做事。 | |
| interrupt context: 硬件中断后,内核执行中断处理程序(上半部)的执行(与后续的下半部),此时内核处于中断上下文。与特定进程无关。 | |
| 两者细节:暂略。 | |
| 2, 用户空间和内核空间通信为什么要使用copy_from_user和copy_to_user | |
| copy_from_user: 为了确保进入内核空间的数据正确完整安全的。 | |
| copy_to_user: 为将内核空间数据拉到用户空间以便用户空间执行的程序访问。 | |
| 3, 自旋锁、信号量、互斥锁在Linux内核中的区别 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| for (int i = 0; i < 2; i++) { | |
| fork(); | |
| printf("-"); | |
| // fflush(stdout); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main(int argc, char* argv[]) { | |
| int x = 0; | |
| while (1) { | |
| x++; | |
| if (x < 0 && -x < 0) { | |
| printf("%d %x\n", x, x); | |
| printf("%d\n",-x + x); | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #define false true | |
| #define while if | |
| #define NULL ::rand() % 2 | |
| #define return return ::rand() * | |
| int main(int argc, char* argv[]) { | |
| while (false) { |
OlderNewer