随笔分类 - Linux
摘要:命名规则: lib + 库的名字 + .a 制作步骤 生成对应.o文件 .c à .o 将生成的.o文件打包 ar rcs + 静态库的名字(libMytest.a) + 生成的所有的.o 发布和使用静态库: 1) 发布静态 2) 头文件 文件如下图所示: 1) 生成对应的.o文件 2) 将所生成的
阅读全文
摘要:man 查看帮助文档 alias ls : 查看命令是否被封装 echo : 显示字符串到屏幕终端 echo $PATH : 将环境变量打印出来 poweroff:关机 rebot:重启 需要管理员权限 vim是从vi发展过来的文本编辑器 命令模式:打开文件之后默认进入命令模式 编辑模式: 末行模式
阅读全文
摘要:mount :设备名 挂载路径 sudo fdisk -l 查看磁盘设备名 sudo mount /dev/sdb1 /mnt sudo umount /mnt 卸载mnt(不能再卸载目录中) 压缩: gzip *.txt (将所有.txt源文件分别压缩.gz压缩包) gunzip 解压缩 bzip
阅读全文
摘要:history 查看历史命令 ctrl+p 向上翻历史纪录 ctrl+n 向下翻历史纪录 ctrl+b 光标向左移动 ctrl+f 光标向右移动 ctrl+a 光标移动到行首 ctrl+e 光标移动到行尾 ctrl+h 删除光标前一个 ctrl+d 删除光标后一个 ctrl+u 删除光标前所有 ct
阅读全文
摘要:有时候我们需要用到线程同步来控制线程运行顺序。 exbot@ubuntu:~/wangqinghe/thread/20190729$ ./synchro 2 thread0 1 thread0 2 thread1 1 thread1 2 thread2 1 thread2 2 thread3 1 t
阅读全文
摘要:int pthread_cancel(pthread_t th); 该函数运行一个线程取消指定的另一个线程th 函数成功,返回0,否则,返回非0; 函数运行结果: exbot@ubuntu:~/wangqinghe/thread/20190729$ ./cancel thread_create su
阅读全文
摘要:int pthread_detach(pthread_t th); pthread_detach函数使线程处于被分离状态。 如果不等待一个线程,同时对线程的返回值不感兴趣,可以设置这个线程为分离状态,让系统在线程退出的时候自动回收它所占用的资源。 一个线程不能自己调用pthread_detach改变
阅读全文
摘要:进程终止时exit()函数,那么线程终止的是什么呢? 线程终止的三种情况: 运行结果: exbot@ubuntu:~/wangqinghe/thread/20190729$ gcc exit.c -o exit -lpthread exbot@ubuntu:~/wangqinghe/thread/2
阅读全文
摘要:有时候在一个线程中创建了另外一个线程,主线程要等到创建的线程返回了,获取该线程的返回值后才退出,这个时候就需要把线程挂起。 int pthread_join(pthread_t th,void ** thr_return); pthread_join函数用去挂起当前线程,直至th指定的线程终止为止。
阅读全文
摘要:strerror() 包含在string.h的函数中 EXIT_SUCCESS 定义包含在stdlib.h的函数中 运行结果: exbot@ubuntu:~/wangqinghe/thread/20190729$ ./thread thread_create success func run...
阅读全文
摘要:运行结果: ubuntu1604@ubuntu:~/wangqinghe/C/20190728$ gedit remove.c b.txt ^C ubuntu1604@ubuntu:~/wangqinghe/C/20190728$ gcc remove.c -o remove ubuntu1604@
阅读全文
摘要:运行结果: exbot@ubuntu:~/wangqinghe/thread/thread_0530$ ./threadcreate thread 1 successcreate thread 2 successthread2:0thread2:1thread2:2thread2:3thread2:
阅读全文
摘要:在linux环境下写c代码时会尝试各种方法或调整路径,需要用到#if 有时候会调整代码,但是又不是最终版本的更换某些值,就需要注释掉,或者需要频繁的来回更换某个变量值测试 就可以用这种方法,只需要更改 if 后面跟的0,1就能达到变换变量值的效果
阅读全文
摘要:makefile文件: make结果: exbot@ubuntu:~/wangqinghe/Transducer/20190611$ makeg++ -c test.cpp g++ test.o -o test 程序运行结果: 运行结果需要用服务器程序互相通信或者使用模拟软件来互相通信。 此处不展示
阅读全文
摘要:main.cpp mysqlInterface.h mysqlInterface.cpp Makefile: 执行结果: make g++ -c main.cpp -I/usr/include/mysql -L/usr/lib/mysql/ -lmysqlclient g++ -c mysqlInt
阅读全文
摘要:参照:https://www.jianshu.com/p/0b2a7cb9a469 创建工作目录,包含一下文件 main.c person.c b.h c.h 如果main.c文件中加上注释的头文件会生成对应的b.h.gch文件,此处存疑 1.创建makefile文件: 2.定义变量,代替目标文件,
阅读全文
摘要:在一个文件夹中建一个c文件 在当前目录下编写makefile文件 解释: 在文件目录下执行make: 首先是test:main.o依赖声明生成test需要main.o文件 make命令检查main.o是否存在(最新) 如果存在(或最新),则执行gcc -o test mian.o命令,生成test;
阅读全文