
Linux环境编程
lightjia
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Linux下设置coredump脚本
linux下调试程序崩溃一般都有coredump生成,可以设置coredump生成路径 #!/bin/sh sed -i '/# End of file/i\* soft core unlimited' /etc/security/limits.conf sed -i '/# End of file/i\* ...原创 2018-11-24 16:08:27 · 728 阅读 · 0 评论 -
日志类简单封装
在程序开发过程中,我们需要动态了解程序运行状况,以及排查问题时程序的调用流程,尤其是在多线程程序中,调用关系用日志记录下来比较重要,方便以后排查问题。以下是自己开发过程中封装的日志功能类。 common.h #ifndef __COMMON__H_ #define __COMMON__H_ #include <stdio.h> #include <stdlib.h> ...原创 2018-04-11 15:17:40 · 1355 阅读 · 0 评论 -
休眠简单封装
1.在多线程后端程序中,我们经常需要等待休眠,如下是自己封装等待休眠的API. #ifndef __CIDLE__H_ #define __CIDLE__H_ #include "common.h" class CIdle { public: CIdle(); ~CIdle(); public: void Sleep(unsigned long iTime = 500); void ...原创 2018-04-11 15:16:20 · 210 阅读 · 0 评论 -
线程简单封装
在后端开发中,我们经常需要使用多线程,频繁的调用系统API创建线程比较繁琐,而且代码有冗余,所以对Linux以及win下的API进行封装。如下是代码实现 #ifndef __CTHREAD__H_ #define __CTHREAD__H_ #include "common.h" #include "CMutex.h" #include "Idle.h" enum THREADSTATE {...原创 2018-04-11 15:15:16 · 346 阅读 · 0 评论 -
Makefile编译
1.多目录编译 SUBDIRS=HdvonBase HdFramework HdThread RECURSIVE_MAKE=@for subdir in $(SUBDIRS);do \ echo "making in $$subdir"; \ (cd $$subdir && $(MAKE)) || exit 1; \ done RECURSIVE_CLEA...原创 2018-07-31 11:42:46 · 590 阅读 · 0 评论 -
Linux下找出CPU过高的线程
确定是CPU过高 使用top观察是否存在CPU使用率过高现象 找出线程 对CPU使用率过高的进程的所有线程进行排序 ps H -e -o pid,tid,pcpu,cmd --sort=pcpu |grep xxx得到如下结果,其中线程2909使用了7.8%的CPU. 2907 2913 0.0 ./xxx 2907 2909 7.8 ./xxx也可以通过查看/proc中的信息来确定高CP...转载 2018-07-24 16:06:26 · 540 阅读 · 0 评论 -
技巧积累
#define exit_if(r, ...) if(r) {printf(__VA_ARGS__); printf("%s:%d error no: %d error msg %s\n", __FILE__, __LINE__, errno, strerror(errno)); exit(1);}原创 2018-02-28 20:53:07 · 181 阅读 · 0 评论 -
C语言柔性数组分配内存
#include #include #include #include #include #include #include #include typedef struct tagNode { size_t len; int key[0]; }Node; int main(int argc, char* argv[]) { Node *n原创 2017-10-13 10:54:40 · 685 阅读 · 0 评论 -
Linux下一个进程重启自己的简单实现
#include #include #include #include #include int main(int argc, char* argv[]) { int fd = open("tmp.txt", O_CREAT | O_APPEND | O_RDWR, 0666); char buf[] = "hello huang jia jia\n"; wr原创 2017-10-12 20:17:19 · 3522 阅读 · 0 评论 -
使用dup2重定向IO流拷贝文件
直接贴代码: #include #include #include #include #include extern int errno; //Author:HuangJiaJia int main(int argc, const char *argv[]) { if(argc < 3) { fprintf(stdout, "USE %s [s原创 2016-04-13 20:09:33 · 324 阅读 · 0 评论