CSAPP leason code
安弦
这个作者很懒,什么都没留下…
展开
-
Fork函数的解析(二)---Signal
1.Sending signals with the kill() function#define N 5int main() { pid_t pid[N]; int i; int child_status; for (i = 0; i < N; i++) if ((pid[i] = fork()) == 0) { //子进程陷入死循环 ...原创 2019-12-08 14:23:58 · 403 阅读 · 0 评论 -
I/O文件的解析
在Linux中一切皆文件,所有的I/O设备(如网络、磁盘和终端)都会被模型化为文件,而所有的输入和输出都被当作对相应文件的读和写来执行。这使得所有的输入输出都能以统一且一致的方式执行:打开文件。内核会返回一个小的非负整数,称为文件描述符,它在后续对此文件的所有操作中标识这个文件。Linux shell 创建的每个进程开始时都有三个自动打开的文件:标准输入(描述符为0)、标准输出(描述符为1)...原创 2019-12-08 14:05:51 · 447 阅读 · 0 评论 -
Fork函数的解析(一)
Fork函数的运用:父进程通过调用Fork函数来创建一个新的子进程。那么,什么是进程呢?进程的经典定义就是一个执行中程序的实例,即指程序的一次运行过程。程序是指按某种方式组合形成的代码和数据集合,代码即是机器指令序列,因而程序是一个静态的概念。不同于程序,进程是具有独立功能的一个程序关于某个数据集合的一次运行活动,因而进程具有动态的含义。1.同一个程序处理不同的数据就是不同的进程。2....原创 2019-11-07 07:41:40 · 649 阅读 · 0 评论 -
可重定位目标文件的解析
从源代码到可执行目标文件要经过以下几个步骤:main.c-----预处理(cpp)-------->main.i------编译(ccl)----->main.s-----汇编(as)----->main.o-----链接(ld)----->main(可执行文件) 可重定位目标文件是.o文件,包含二进制的代码和数据,其形式可以在编译时和其它的可重定位目标文...原创 2019-10-08 23:21:39 · 1071 阅读 · 0 评论 -
Float Sum(浮点数的加法)
#include <stdio.h>#include <stdlib.h>#include <string.h>#define BUFSIZE 256int main(int argc, char *argv[]) { char prefix[BUFSIZE]; char next[BUFSIZE]; int i; floa...原创 2019-05-25 20:18:46 · 4679 阅读 · 0 评论 -
Example of deep recursion (深递归的例子)
/* Example of deep recursion *//*递归太深堆栈溢出*/#include <stdio.h>#include <stdlib.h>int recurse(int x) { int a[1<<15]; /* 4 * 2^15 = 128 KB */ printf("x = %d. a at %p\n"...原创 2019-05-25 20:01:20 · 261 阅读 · 0 评论 -
Convert sequence of hex digits
/* Convert sequence of hex digits on command line into a string, terminated by \n */#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]) { int i; for (i = 1; i...原创 2019-05-25 19:42:16 · 182 阅读 · 0 评论 -
Pointer Locate
#include <stdlib.h>#include <stdio.h>#include <unistd.h> /*Unix Standard 用于系统调试*//* P是一个指针变量的名字表示指针变量指向的内存地址,*p是所指对象的内容,&p指针p的地址*/static void show_pointer(void *p, char...原创 2019-05-25 19:25:42 · 138 阅读 · 0 评论 -
Demonstration of buffer overflow (缓冲区溢出的事例)
/* Demonstration of buffer overflow *///缓冲区溢出的示范#include <stdio.h>#include <stdlib.h>/* Implementation of library function gets() */char *gets(char *dest) /*指针函数*/{ int ...原创 2019-05-25 18:29:34 · 221 阅读 · 0 评论 -
Memory Referencing Bug Example
#include <stdio.h>#include <stdlib.h>typedef struct { int a[2]; double d;} struct_t;double fun(int i) { volatile struct_t s; /*可更新的变量没有固定的值*/ s.d = 3.14; s....原创 2019-05-25 16:15:58 · 486 阅读 · 0 评论 -
计算平方根(注意范围否则有可能溢出)
#include <stdio.h>#include <stdlib.h>int sq(int x) { return x*x;}int main(int argc, char *argv[]) { /*第一个参数表示入口参数的个数*/ int i; for (i = 1; i < argc; i++) { int x =...原创 2019-05-25 10:22:28 · 871 阅读 · 0 评论 -
补码数的符号扩展
short sx = -12345; /*-12345*/unsigned short usx = sx; /*53191*/int x = sx; /*-12345*/unsigned ux = usx; /*53191*/printf("sx = %d:\t",sx);show_bytes((byte_point...原创 2019-05-25 10:00:18 · 4277 阅读 · 2 评论 -
show-bytes-prints byte representation of data
/* show-bytes - prints byte representation of data *//* $begin show-bytes */#include <stdio.h>/* $end show-bytes */#include <stdlib.h>#include <string.h>/* $begin show-bytes *...原创 2019-05-25 09:31:53 · 144 阅读 · 0 评论