Linux 和 多线程
每次都是用到,查一下,写下,这次稍微记录下笔记。
和Thread相关,基本的有3个概念:线程的建立和销毁;线程锁;线程条件
关于建立线程:
ret = pthread_create(&thread_id, NULL, Do_Thread, &Do_Thread_Para);
// 第2参数是thread 属性,一般我不用设置
// 第4个参数是Do_Thread的入口参数,一般我传一个结构体进去
关于销毁线程:
等待线程结束:pthread_join
强行杀掉线程:pthread_exit
让线程自生自灭:pthread_detach
我一般用的是第一个:
pthread_join(thread_id, &Do_Thread_ret);
// 第二个参数是线程返回值
关于线程锁:当要在多个线程共享某些变量的时候,就需要用锁。这样可以保证一个时间点,只有一个线程能够访问这个线程
pthread_mutex_t mMutexData;
pthread_mutex_init(&(mMutexData), NULL); // 第2个参数是锁的属性,我一般用默认,NULL
pthread_mutex_lock(&mMutexData); // 加锁
pthread_mutex_unlock(&mMutexData) // 去锁
pthread_mutex_destroy(&mMutexData) // 销毁
关于条件:当某个线程需要等待其他线程处理完某个数据(运行到某个点)的话,就需要用条件,一般加个时间参数,以防止死等下去。
pthread_cond_t *sConditionData;
pthread_cond_init(&(sConditionData), NULL); // 第2个参数是锁的属性,我一般用默认,NULL
pthread_mutex_lock(&mMutexData); // 一般条件必须和锁加在一起用,以保证条件变量不重入
pthread_cond_signal(&sConditionData); // 发信号
pthread_mutex_unlock(&mMutexData);
struct timespec ts;
struct timeval sTime;
struct timezone sTimeZone;
long res;
pthread_mutex_lock(&(pApp->mMutexData));
gettimeofday(&sTime, &sTimeZone);
ts.tv_sec = sTime.tv_sec;
ts.tv_nsec += 5sTime. tv_usec * 1000 +20*1000*1000; // 20 ms
ret = pthread_cond_timedwait(&(pApp->sConditionData), &(pApp->mMutexData), &ts); // 等候
if(ret == ETIMEDOUT)
{
pthread_mutex_unlock(&(pApp->mMutexData));
 
相关文档:
在Linux操作系统中,有一个系统软件包,它的功能类似于Windows里面的“添加/删除程序”,但是功能又比“添加/删除程序”强很多,它就是Red Hat Package Manager(简称RPM)。此工具包最先是由Red Hat公司推出的,后来被其他Linux开发商所借用。由于它为Linux使用者省去了很多时间,所以被广泛应用于在Lin ......
samba实现ubuntu跟windows文件共享
一. Samba 简介
Samba(SMB是其缩写) 是一个网络服务器,用于Linux和Windows共享文件之用;Samba 即可以用于Windows和Linux之间的共享文件,也一样用于Linux和Linux之间的共享文件;不过对于Linux和Linux之间共享文件有更好的网络文件系统NFS,NFS也是需要架设服务器的;
大家知 ......
/*
* /*
* Linux x86 Dropbear SSH <= 0.34 remote root exploit
* coded by live
*
* You'll need a hacked ssh client to try this out. I included a patch
* to openssh-3.6.p1 somewhere below this comment.
*
* The point is: the buffer being exploited is too small(25 bytes) to hold our
......
利用
下载的这段代码,成功实现了守护进程,原来守护进程是很简单的事情。
在main函数中执行
init_daemon();//初始化为Daemon
就可以把进程变成守护进程
#include
#include
#include
#include
#include
void
init_daemon(void
)
{
int
pid;
int
i;
if
(pid=fork()) ......
oracle dataguard是指一种数据库级别的HA方案,最主要的功能是容灾,数据保护,故障恢复等
在生产数据库的事务一致性时,使用产生的物理全备份创建备库,备库通过传输过来的归档日志自动维护备用数据库
将重做的数据应用到备用库上。
1,前提:
primary:192.168.18.1;
oracle_SID:db1
  ......