操作系统

挂起

进程


命令行参数

进程地址空间
进程会认为自己独占系统资源


页表映射

为什么存在地址空间



进程控制
fork函数
进程退出
进程等待
#include<sys/types.h> #include<sys/wait.h>
wait函数
pid_t wait(int*status);
返回值:
成功返回被等待进程pid,失败返回-1。参数:
输出型参数,获取子进程退出状态,不关心则可以设置成为NULL
wait_pid:
pid_ t waitpid(pid_t pid, int *status, int options);
返回值:
当正常返回的时候waitpid返回收集到的子进程的进程ID;
如果设置了选项WNOHANG,而调用中waitpid发现没有已退出的子进程可收集,则返回0;如果调用中出错,则返回-1,这时errno会被设置成相应的值以指示错误所在;
参数: pid:
Pid=-1,等待任一个子进程。与wait等效。
Pid>0.等待其进程ID与pid相等的子进程。status:
WIFEXITED(status): 若为正常终止子进程返回的状态,则为真。(查看进程是否是正常退出)
WEXITSTATUS(status): 若WIFEXITED非零,提取子进程退出码。(查看进程的退出码) options:
WNOHANG: 若pid指定的子进程没有结束,则waitpid()函数返回0,不予以等待。若正常结束,则返回该子进程的ID。


非阻塞轮询等待

进程程序替换
替换函数
有六种以exec开头的函数,统称exec函数
#include <unistd.h>`
int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg, ...,char *const envp[]);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
这些函数如果调用成功则加载新的程序从启动代码开始执行,不再返回。
如果调用出错则返回-1
所以exec函数只有出错的返回值而没有成功的返回值


替换原理:
指定程序的代码加载到指定为止 覆盖代码和数据


代码写时拷贝

基础IO
文件

接口介绍
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode);
pathname: 要打开或创建的目标文件
flags: 打开文件时,可以传入多个参数选项,用下面的一个或者多个常量进行"或"运算,构成flags。参数:
O_RDONLY: 只读打开O_WRONLY: 只写打开O_RDWR : 读,写打开
这三个常量,必须指定一个且只能指定一个
O_CREAT : 若文件不存在,则创建它。需要使用mode选项,来指明新文件的访问权限O_APPEND: 追加写
O_TRUNC
:如果文件存在,清空
返回值:
成功:新打开的文件描述符
失败:-1

库是系统调用的封装


文件fd
重定向的本质

FILE


缓冲区
磁盘简介
物理结构

逻辑结构





软硬链接

动静态库

