随笔分类 -  Linux

摘要:服务器端 #include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <stdlib.h> #include <ctype.h> #include <arpa/inet.h> #include <sys/types. 阅读全文
posted @ 2020-06-05 16:07 feibilun 阅读(175) 评论(0) 推荐(0)
摘要:trylock: #include <stdio.h> #include <unistd.h> #include <pthread.h> int beginnum=1000; pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER; void* thr_ 阅读全文
posted @ 2020-05-25 10:38 feibilun 阅读(177) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> #includ 阅读全文
posted @ 2020-05-19 21:56 feibilun 阅读(195) 评论(0) 推荐(0)
摘要:man 7 signal (默认处理动作) 杀死父进程: 由父进程杀死3号子进程: raise 函数,给本进程传递信号 abort 函数 setitimer 函数 (实现alarm) (第一次5s发SIGALRM,之后每隔3s发一次。signal()函数用于捕捉信号) 实现alarm 信号集处理函数 阅读全文
posted @ 2020-03-15 22:08 feibilun 阅读(152) 评论(0) 推荐(0)
摘要:(read默认是阻塞的,会一直等着,直到读到,所以会打印) 实现 ps aux | grep bash #include <stdio.h> #include <unistd.h> int main() { int fd[2]; pipe(fd); pid_t pid = fork(); if(pi 阅读全文
posted @ 2020-03-09 17:15 feibilun 阅读(244) 评论(0) 推荐(0)
摘要:PCB 进程控制块 getenv 获取环境变量 父进程先死,子进程变为孤儿。 加sleep,让父进程最后死。 查看进程信息: ps aux 有ppid信息: ps ajx 杀死进程: kill -9 pid kill表示给进程发信号,-9表示发9号信号 kill -l 查看信号信息 生5个子进程 精 阅读全文
posted @ 2020-03-04 15:53 feibilun 阅读(248) 评论(0) 推荐(0)
摘要://-rw-rw-r-- 2 zijiao zijiao 16 Feb 24 13:20 hello #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl 阅读全文
posted @ 2020-02-29 17:20 feibilun 阅读(251) 评论(0) 推荐(0)
摘要:1. OPEN umask=2, 666&(~2)=664 2. CLOSE 3. Read 4. write 模拟 cat: 需求: 写hello到一个文件,然后读取,输出到终端。 若这样写,read不到,因为写hello后将到文件末尾。 需要lseek lseek 计算文件大小 少了一句: cl 阅读全文
posted @ 2020-02-21 16:51 feibilun 阅读(152) 评论(0) 推荐(0)
摘要:使用gdb: 编译时加-g参数 gcc -o app -I ./ func.c main.c -g 启动gdb: gdb app 在gdb启动程序: r(un) 启动 start 启动 停留在main函数,分步调试 n(ext) 下一条语句 s(tep) 下一条语句,可以进入到函数内部 q(uit) 阅读全文
posted @ 2020-02-21 10:09 feibilun 阅读(145) 评论(0) 推荐(0)
摘要:makefile 三要素: 目标 依赖 规则命令 写法: 目标:依赖 规则命令 v1: 缺点: 如果更改其中一个文件,所有源码都需要重新编译 可以考虑编译过程分解,先生成.o文件,使用.o文件得到结果 v2: 这样做的话,如果改变main.c,只需重新编译main.c, add.c sub.c无需重 阅读全文
posted @ 2020-02-20 17:57 feibilun 阅读(113) 评论(0) 推荐(0)
摘要:静态库文件命名: libxxx.a 制作步骤: 1. 编译为.o文件 2.将.o文件打包: ar rcs libxxx.a file1.o file2.o 3.将头文件与库一起发布 使用: gcc main.c -o app -I ./include/ -L lib/ -lxxx 动态库文件命名: 阅读全文
posted @ 2020-02-18 22:12 feibilun 阅读(134) 评论(0) 推荐(0)
摘要:1. copy:yy (当前行) ,5yy(当前以及下面共五行) 正常模式下2. paste:p 正常模式下复制到光标下一行 P 复制到当前行 3. delete one line: dd, 5dd(5 lines) 正常模式下 4. x 删除光标位置内容 5. dw 删除一个单词 6. d$ 删除 阅读全文
posted @ 2020-02-18 17:51 feibilun 阅读(111) 评论(0) 推荐(0)