上一页 1 ··· 34 35 36 37 38 39 40 41 42 ··· 60 下一页

2016年9月11日

Linux 进程与线程四(加锁--解锁)

摘要: pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;int pthread_mutex_lock(pthread_mutex_t *mutex);int pthread_mutex_unlock(pthread_mutex_t *mutex);PTHREA 阅读全文

posted @ 2016-09-11 17:51 寒魔影 阅读(11759) 评论(0) 推荐(0)

Linux 进程与线程三(线程比较--创建线程参数)

摘要: int pthread_equal(pthread_t th1,pthread_t th2); pthread_equal函数比较th1与th2是否为同一线程,由于不可以讲pthread_t数据类型认为是整数,所以也不能用比较整数的方式比较pthread_t。 如果th1与th2相同,函数返回非0值,如果不同函数返回0。 线程属性 --以前调用pthread_create传入的attr参数都... 阅读全文

posted @ 2016-09-11 09:57 寒魔影 阅读(876) 评论(0) 推荐(0)

2016年9月10日

Linux 进程与线程二(等待--分离--取消线程)

摘要: int pthread_join(pthread_t thr,void **thr_return); pthread_join函数用于挂起当前线程,直至th指定的线程终止为止。 如果另一个线程返回值不是NULL,则保存在thr_return地址中。 一个线程所使用的内存资源在应用pthread_join调用之前不会被重新分配,所以对于每个线程必须调用一次pthread_join函数(被分离线程除... 阅读全文

posted @ 2016-09-10 22:40 寒魔影 阅读(2123) 评论(0) 推荐(0)

Linux 进程与线程一(创建-关闭线程)

摘要: 进程是一个实体。每一个进程都有他自己的内存地址段(heap,stack等等) 进程是执行中的程序。 程序是一个没有生命的实体,只有处理器赋予程序生命时,它才能成为一个活动的实体。 进程是操作系统中最基本、重要的概念。 线程,又是被称为轻量级进程(Lightweight Process LWP),是程序执行的最小单元。 每一个程序都至少有一个线程,若程序只有一个线程,那么就是程序本身。 单线程的进... 阅读全文

posted @ 2016-09-10 19:09 寒魔影 阅读(22922) 评论(0) 推荐(1)

Linux 守护进程二(激活守护进程)

摘要: //守护进程--读文件 #include #include #include #include #include #include #include #include #include #include "mylog.h" //监听管道 void listenfifo() { //file size int len=0; int fd2=0; ... 阅读全文

posted @ 2016-09-10 17:17 寒魔影 阅读(706) 评论(0) 推荐(0)

2016年9月8日

Linux Linux程序练习八

摘要: 题目:自己动手实现一个守护进程,当控制台窗口关闭时还可以在后台运行。每隔一秒钟向my.log文件中插入一条记录,记录格式如下:yyyy-mm-dd hh:mi:se 记录内容,其中yyyy为年,mm为月,dd为天,hh为小时,mi为分钟, se为秒。 #ifdef __cplusplus extern "C" { #endif //写日志函数 //path:日志文件名 //msg:日志信... 阅读全文

posted @ 2016-09-08 13:39 寒魔影 阅读(375) 评论(0) 推荐(0)

2016年9月7日

Linux共享库 日志方法

摘要: mylog.h mylog.c makefile 阅读全文

posted @ 2016-09-07 23:32 寒魔影 阅读(564) 评论(0) 推荐(0)

Linux Linux程序练习七

摘要: 题目:实现两个程序mysignal、mycontrl,mycontrl给mysignal发送SIGINT信号,控制mysignal是否在屏幕打印“hello”字符串。 //捕捉信号 #include #include #include #include #include #include int flag=0; void catch_sig(int sign) { ... 阅读全文

posted @ 2016-09-07 22:06 寒魔影 阅读(515) 评论(0) 推荐(0)

Linux Linux程序练习六

摘要: upper.h upper.c test1.c 运行结果 阅读全文

posted @ 2016-09-07 21:16 寒魔影 阅读(404) 评论(0) 推荐(0)

Linux Linux程序练习五

摘要: 题目:编写两个进程a和b,利用共享内存技术,a向共享内存写字符串,b将从共享内存中读到的字符串在屏幕上打印出来。 //创建共享内存区 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #inc 阅读全文

posted @ 2016-09-07 21:14 寒魔影 阅读(424) 评论(0) 推荐(0)

上一页 1 ··· 34 35 36 37 38 39 40 41 42 ··· 60 下一页

导航