随笔分类 - 环境编程
摘要:rand()函数不接受参数,默认以1为种子(即起始值)。 随机数生成器总是以相同的种子开始,所以形成的伪随机数列也相同,失去了随机意义。(但这样便于程序调试) srand()函数就是指明种子的大小;只要种子不同,那么每次随机到的值或者固定范围的序列就不一样,达到完全随机。 代码1.给固定的种子,每次
阅读全文
摘要:进程:一个程序的一次执行过程,是系统调度的单位,资源管理和程序执行的最小单位,线程是调度的最小单位。 程序:是静态的,是一个可执行文件,保存在硬盘上的一些指令的有序集合。 进程的执行过程:指令和数据是存放在硬盘上的,这是前提。首先运行程序---》系统会将硬盘上的指令和数据加载到内存中,(如果cpu每
阅读全文
摘要:进程: 优点:多个进程并发执行,能够参与系统调度,是资源管理和程序执行的最小单位。 缺点:占用资源(无论哪种通信方式都需要创建第三方),效率低下(每次对数据的访问都需经过第三方),系统开销大(进程退出需要保存,执行需要加载资源)。 线程: 优点:多个线程并发执行--à系统调度的最小单位。 与进程共享
阅读全文
摘要:系统io读写,copy int main(int argc, char **argv) { if(argc != 3) { printf("Usage: %s <src> <dst>\n", argv[0]); exit(0); } int fd1, fd2; fd1 = open(argv[1],
阅读全文
摘要:fstat ,lstat,stat; 头文件:#include<sys/stat.h> #include<sys/types.h> #include<unistd.h> 定义函数: (1)int stat(const char *file_name,struct stat *buf) 返回一个与此命
阅读全文
摘要:1.定义一个任务结构体,和一个线程池结构体 struct task{ void *(*p)(void*);//需要实现的函数; void *arg;//函数所带的参数 struct task *next;};struct pthread_pool{ pthread_mutex_t mutex;//线
阅读全文
摘要:int main(){ printf("abc\n"); pid_t r = fork();//子进程从fork()的下条语句开始运行,标准答案是从fork的后半部分开始运行 if(r==0) { printf("getpid = %d\n",getpid()); printf("getppid =
阅读全文
摘要:思路:打开一个空文件,不断向文件中写入一个字符,一个字符占一个字节,num++判断info.st_size中是否有数据,一旦有数据,立刻break。 然后输出num. #include<stdlib.h>#include<stdio.h>#include<string.h>#include<erro
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#include<errno.h>#include<unistd.h>#include<strings.h>#include<stdbool.h> #inclu
阅读全文
摘要:在使用这个结构体和方法时,需要引入: <sys/types.h> <sys/stat.h> struct stat这个结构体是用来描述一个linux系统文件系统中的文件属性的结构。 可以有两种方法来获取一个文件的属性: 1、通过路径: int stat(const char *path, struc
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#include<errno.h>#include<unistd.h>#include<strings.h>#include<stdbool.h> #inclu
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#include<errno.h>#include<unistd.h>#include<strings.h>#include<stdbool.h> #inclu
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#include<errno.h>#include<unistd.h>#include<strings.h>#include<stdbool.h> #inclu
阅读全文
摘要:1.非指针的操作 char buff[100]; bzero(buff,100);将buff中最开始的n个字节清空; struct stat fileinfo; bzero(&fileinfo, sizeof(fileinfo)); ----------------- struct stat fil
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#include<errno.h>#include<unistd.h>#include<strings.h>#include<stdbool.h> #inclu
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#include<errno.h>#include<unistd.h>#include<strings.h>#include<stdbool.h> #inclu
阅读全文
摘要:#include<stdlib.h>#include<stdio.h>#include<unistd.h>#include<errno.h>#include<error.h>#include<string.h>int main(int argc ,char **argv){ if(argc != 2
阅读全文
摘要:关于库================1,静态库和动态库 1.1 静态库:书店(卖出去) (优点:速度稍快,不依赖库 缺点:浪费存储空间) 1.2 动态库:图书馆(借用) (缺点:速度稍慢,依赖于库 优点:节省大量空间)(更常用) 2,制作静态库:(以example1.c、example2.c,假设
阅读全文
摘要:diff diir_1.0/ dir_2.0/ -urNB > dir_2.0.patch u:union以合并的格式来输出文件的差异信息 r:递归的对比所有的子目录下的文件 U:将不存在的文件视为空文件 B:忽略空行引起的差异 ~/dir_1.0$ patch -p1< ../dir_2.0.pa
阅读全文