多线程并发
fork函数调用过程1static inline _syscall0(int,fork)
_syscall0是一个宏实现,实现了可复用的函数模板
123456789101112#define _syscall0(type,name) \type name(void) \{ \long __res; \__asm__ volatile ("int $0x80" \ : "=a" (__res) \ : "0" (__NR_##name)); \if (__res >= 0) \ return (type) __res; \errno = -__res; \return -1; \}
这里fork可转化为
123456789101112int fork(void) { volatile long __res; _asm { _asm mov eax,__NR_fork _asm int 80h _asm mov __res,ea ...
作业调度算法
PCB进程控制块PCB(process control block)称为进程控制块。
一个程序并不是从头到尾一次执行的。进程控制块可以保存进程的上下文。
12345678910111213141516171819202122232425262728293031323334//进程控制块struct task_struct {/* these are hardcoded - don't touch */ long state; /* -1 unrunnable, 0 runnable, >0 stopped */ long counter; long priority;/*优先级*/ long signal; struct sigaction sigaction[32]; long blocked; /* bitmap of masked signals */ /* various fields */ int exit_code; unsigned long start_code,end_code,end_data,brk,start_stack; lon ...
signal
信号信号的位置:/usr/include/signal.h
信号的分类
标准信号/不可靠信号:信号标识符1-32,不处于信号队列中,只能接收一次
实时信号/可靠信号:信号标识符32-64,同一信号可以发送多次,被多次接收,存储在sigqueue中
信号的特点
不可预测/随机性
传送数据简单,信号描述符
信号的状态
generation
delivery
信号的产生
键盘快捷键
系统调用函数
内核产生:硬件异常,被除数为0信号可以由线程产生,也可以由内核产生,但内核产生的终止信号通常是致命的
信号的响应
默认:SIG_DEF通常是终止
忽略:SIG_IGN
用户自定义
==SIGKILL和SIGSTOP的默认行为不能修改,不能被忽略==
内核在信号中扮演的角色
当操作系统从内核态切换为用户态时,会检测==pending&~blocked==位图,如果位图置1则执行信号处理程序
多线程程序中的信号处理函数
对于多线程程序,kill函数会把信 ...
文件系统
文件描述符元数据inodeinode保存文件的属性,执行块区域
inode并不保存文件名
inode表
inode位图
block块
数据块block一个文件保存在一个或多个块中
保存了文件的内容数据,文件读取的最小单位
限流算法
令牌桶限流恒定速率生成令牌,有请求到来时根据是否具有令牌来决定是否接受请求
应用限流
流媒体传输
api请求
资源管理
滑动窗口算法
指针
指针函数指针函数是指返回类型为函数指针类型
function函数返回一个返回值为空,参数值为int类型的函数指针。
1void (*fun)(int) funtion();
函数指针函数指针:指向函数入口的指针
函数指针的定义函数返回值 (*point)(参数类型);
1int (*FUNC_POINT)(float);
上面代码声明了一个返回值为int,参数类型为float的函数指针
typedef与函数指针
12typedef int(*func)(int) FUNC;FUNC f1;//得到函数指针 int(*f1)(int)
函数指针的初始化123456789#include<stdio.h>int add(int x,int y){ printf("%d+%d=%d\n",x,y,x+y);}int main(){ int (*func)(int,int); func=add; func(1,2);}
123456789#include<stdio.h>int add(in ...
linux系统调用
linux系统调用分类The linux kernel provide some api to opearte the system,some usually used api loke like read,write which aoubt IO
IO
user manage
file param
mutial pthread
linux操作系统常用的系统调用
文件操作
进程控制
用户
文件IOin the linux,every thing can abstract to file.the operation of the hardware device or input output stream can be sum up to read,write,open,close,seek.
in the file systeam,every file have unique identity called file descriptor ,the type of file descriptor is int.when a new file stream create,the ...
c标准
C的标准
c标准
年份
Classic C
1978
ANSI C
1989
ISO C90
1990
ISO C99
1999
ISO C11
2011
ISO C17
2017
C99inline内联函数
restrictrestrict是类型限定符,它主要用于指示指针之间的别名关系,从而允许编译器进行更有效的优化。
restrict的声明
1int* restrict p;
123typedef int * POINT;POINT restrict p2;Point p2 restrict;
restrict修饰指针,表示该指针是访问该指针所指向对象的唯一方法,不存在指针别名(多个指针执行同一块内存区域)的情况
restrict 语义仅应用于左值(可赋值的内存位置)表达式
_Bool布尔宏
_Complex复数宏
_ImaginaryC17