随笔分类 -  Linux

上一页 1 2

线程共享全局变量和私有全局变量
摘要:共享全局变量实例:#include #include #include #include int key=100;void *helloworld_one(char *argc){ printf("the message is %s\n",argc); key=10; printf... 阅读全文

posted @ 2014-06-15 16:27 lakeone 阅读(3002) 评论(0) 推荐(0)

线程退出前操作
摘要:#include #include #include #include void cleanup(){ printf("cleanup\n");}void *test_cancel(void){ pthread_cleanup_push(cleanup,NULL); printf(... 阅读全文

posted @ 2014-06-15 11:47 lakeone 阅读(191) 评论(0) 推荐(0)

Linux下线程pid和tid
摘要:#include #include #include #include struct message{ int i; int j;};void *hello(struct message *str){ printf("child, the tid=%lu, pid=%d\n",pt... 阅读全文

posted @ 2014-06-15 09:29 lakeone 阅读(31735) 评论(0) 推荐(1)

消息队列实现实时通信
摘要:此实例是一个简单的使用消息队列进行实时聊天的本机通信程序,,发送端每发送一个消息,会立即被接收读取,在没有消息在消息队列中时,将处于阻塞状态。终端1运行接收端#include #include #include #include #include #include #include struct m... 阅读全文

posted @ 2014-06-13 15:27 lakeone 阅读(730) 评论(0) 推荐(0)

IPC机制key值的各位组成
摘要:key_t ftok(const char *_pathname, int _proj_id)key值的第31~24位为ftok()第二个参数的低8位;key值的第23~16位为ftok()第一个参数文件属性的st_dev成员的低8位;key值的第15~0位为ftok()第一个参数文件属性的st_i... 阅读全文

posted @ 2014-06-12 20:00 lakeone 阅读(907) 评论(0) 推荐(0)

ctrl+c,ctrl+d,ctrl+z在linux中意义
摘要:#include #include #include #include #include #include #define BUFFER_SIZE 1024int main(int argc, char *argv[]){ int fd; char buffer[BUFFER_SIZE]... 阅读全文

posted @ 2014-06-09 09:17 lakeone 阅读(543) 评论(0) 推荐(0)

Linux x86_64与i386区别之 —— 内存寻址
摘要:毫无疑问,不管是32位,还是64位处理器,所有进程(执行的程序)都必须占用一定数量的内存,它或是用来存放从磁盘载入的程序代码,或是存放取自用户输入的数据等等。不过进程对这些内存的管理方式因内存用途不一而不尽相同,有些内存是事先静态分配和统一回收的,而有些却是按需要动态分配和回收的。对任何一个普通进程... 阅读全文

posted @ 2014-05-12 15:33 lakeone 阅读(4940) 评论(0) 推荐(0)

修改进程当前工作路径
只有注册用户登录后才能阅读该文。

posted @ 2014-05-10 12:08 lakeone 阅读(4) 评论(0) 推荐(0)

readdir_r()读取目录内容
摘要:readdir()在多线程操作中不安全,Linux提供了readdir_r()实现多线程读取目录内容操作。#include #include #include int main(void){ DIR* dirp; struct dirent *dp1=malloc(sizeof(stru... 阅读全文

posted @ 2014-05-10 11:37 lakeone 阅读(2904) 评论(1) 推荐(0)

Linux下列出某目录下非隐藏文件基本信息
只有注册用户登录后才能阅读该文。

posted @ 2014-05-10 11:17 lakeone 阅读(2) 评论(0) 推荐(0)

memmove和memcpy
摘要:1.memmove函数原型:void *memmove(void *dest, const void *source, size_t count)返回值说明:返回指向dest的void *指针参数说明:dest,source分别为目标串和源串的首地址。count为要移动的字符的个数函数说明:memm... 阅读全文

posted @ 2014-05-09 17:03 lakeone 阅读(341) 评论(0) 推荐(0)

sscanf的应用
摘要:1.提取字符串2.提取指定长度的字符串3.提取指定字符为止的字符串4.取仅包含指定字符集的字符串5.取到指定字符集为止的字符串#include int main(){ char str[512]={0}; sscanf("123456","%s",str); printf("str... 阅读全文

posted @ 2014-05-02 12:11 lakeone 阅读(148) 评论(0) 推荐(0)

获取CPU频率
摘要:#include #include float get_cpu_clock_speed(){ FILE *fp; char buffer[1024]; size_t bytes_read; char *match; float clock_speed; fp=fo... 阅读全文

posted @ 2014-05-02 11:58 lakeone 阅读(1039) 评论(0) 推荐(0)

打印随机数到字符串中
摘要:#include #include #include int main(){ srand(time(0)); char s[64]; int offset=0; int i; for(i=0;i<10;i++) { offset+=sprintf(s... 阅读全文

posted @ 2014-05-02 11:40 lakeone 阅读(184) 评论(0) 推荐(0)

printf/scanf格式
摘要:(1)打印字符char c;printf("%c",c);(2)打印整形int i;printf("%d",i); //有符号十进制数printf("%u",i); //无符号十进制数(3)打印浮点数float f;printf("%f",f);(4)打印指针int *p;pri... 阅读全文

posted @ 2014-05-02 10:57 lakeone 阅读(241) 评论(0) 推荐(0)

用fread和fwrite实现文件复制操作
摘要:#include #include #include int main(int argc,char **argv){ FILE *fp_src,*fp_des; char buf[128]; int num; if(argc!=3) { printf("t... 阅读全文

posted @ 2014-05-02 10:33 lakeone 阅读(1857) 评论(0) 推荐(0)

用fseek和ftell获取文件的大小
摘要:#include #include #include int main(int argc,char *argv[]){ int n=0; FILE *fp; if((fp=fopen(argv[1],"r"))==NULL) { perror("fopen");... 阅读全文

posted @ 2014-05-02 09:54 lakeone 阅读(957) 评论(0) 推荐(0)

ecl函数的用法
摘要:相关函数fork, execle, execlp, execv, execve, execvpWindows下头文件#include Linux下头文件#include 函数定义int execl(const char *path, const char *arg, ...);函数说明execl()... 阅读全文

posted @ 2014-05-02 09:46 lakeone 阅读(488) 评论(0) 推荐(0)

判断标准I/O的缓冲区类型
摘要:#include void pr_stdio(const char *, FILE *);int main(){ FILE *fp; fputs("enter any character\n",stdout); if(getchar()==EOF) printf("getchar error");... 阅读全文

posted @ 2014-05-01 12:11 lakeone 阅读(361) 评论(0) 推荐(0)

上一页 1 2

导航