关于Solaris2.6上的多进程通信问题.100分给高手! 这个问题难啊,需要亲自调试,应该是PV操作的问题,建议:仔细查一下PV操作的顺序。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我觉得THREAD1并不一定需要,可由FTP进程直接写FILELIST,至于子进程WAIT你是否用SIGCHLD信号控制比较方便 终于,有人回答了!一定给分!FILELIST不是共享内存,它只在Main进程中可见。SIGCHLD是解决有进程wait不到的方法,但一定要wait,否则会造成很多僵尸进程的存在。谁对pipe 或线程同步熟悉?!帮忙看看! >thread1不知道为什么block在read pipe,尽管ftp process 还在write pipe?不可能吧,PIPE的读端没有读出,写端怎么可能不停的写呢,PIPE的容量是多少?对FILELIST与PROCESS_COUNTER操作的时候加锁了吗把代码帖出来看看. 先说filelist:int file_num=0;RWTPtrSlist<RWCString> filelist;//是用Rogue Wave的库,方法有insert(), get()...认为是数组吧.mutex_t filelist_mutex;cond_t filelist_cond; //fork ftp processif (mutex_init(&filelist_mutex, USYNC_THREAD, NULL)!= 0) {...}//and init all mutex and cond//creat 2 thread...//in readpipe threadif (mutex_lock(&filelist_mutex)!=0) { ...}filelist.insert(...);file_num++;if (cond_signal(&filelist_cond)!=0) {...}if (mutex_unlock(&filelist_mutex)!=0) {...}//in Mainif (mutex_lock(&filelist_mutex)!=0) { ...}while (file_num==0) { thr_result = cond_wait(&filelist_cond, &filelist_mutex); if (thr_result!=0) { if (thr_result!=EINTR) { exit(0); } else { continue; } }}filename=filelist.get(); //remove one file name from filelistfile_num--; if (mutex_unlock(&filelist_mutex)!=0) {...}//then fork1 deal file process to deal filename 我已经去掉waitpid thread, 改为在注册的signal(SIGCHLD)处理函数sig_chld中waitpid, 以防止有进程wait不到mutex_t counter_mutex;cond_t counter_cond; //fork ftp processif(signal(SIGCHLD,sig_chld)==SIG_ERR){...}if (mutex_init(&counter_mutex, USYNC_THREAD, NULL)!= 0) {...}//init all mutex and cond//creat read pipe thread//in Main while(1) loop and after get filenameif ( (pid_sql = fork1()) < 0) {...}else if (pid_sql > 0) { /* parent */ if(mutex_lock(&counter_mutex)!= 0) { ... } while (process_counter >=max_file_num) { //max_file_num=30 thr_result = cond_wait(&counter_cond, &counter_mutex); if (thr_result!=0) { if (thr_result!=EINTR) { kill(pid_ftp, SIGUSR1); exit(0); } else continue; } } } process_counter++; if (mutex_unlock(&counter_mutex)!=0) { ... }}//pid_sql==0 child ...-----------------------------------------------------------------void sig_chld(int signo){ signal(SIGCHLD,sig_chld); int status; pid_t pid_son; if(signo==SIGCHLD){ if(mutex_lock(&counter_mutex)!= 0) { kill(pid_ftp, SIGUSR1); exit(1); } if(process_counter>0){//目前测试从未<0 //ftp 没计算在process_counter中,如ftp exit,有可能(process_counter--)<0 process_counter--; } else{ ... } if (cond_signal(&counter_cond)!=0) { kill(pid_ftp, SIGUSR1); exit(1); } if (mutex_unlock(&counter_mutex)!=0) { kill(pid_ftp, SIGUSR1); exit(1); } if ((pid_son=waitpid(-1,&status,WNOHANG)) > 0) { if (pid_son == pid_ftp) { //ftp process exit and should exit! kill(pid_ftp, SIGUSR1); exit(1); } } else{ ... } } return;} pipe问题的确很奇怪,我还没有找到原因.pipe最大4*1024 or 2*1024 建议去掉thread1,没有一点用,还复杂了。在主线程中read pipe 即可。感觉上read pipe 不会有问题。如果实在没办法,不如用更可靠的通信机制,如socket? 一个VB实例求解错误 如何更新窗口样式 提问:刚才我散分是谁帮我给的分呀?一头雾水! 哪里有水晶报表的学习资料下载?? 我写的FTP上传程序上传只有数字的文本文件,上传成功后,里面格式不变,但只要有汉字在里面,上传后的文件格式就乱了,还有乱码,里面的内容也 请教:如何解决下标越界问题?? 求救,菜单问题!!! vb多层循环优化问题 在VB6中如何使用通讯控件的编程 如何实现:每次只能有该程序的一个实例在运行,并且如果已经有该程序的实例在运行,就激活它? 概念:WINDOWS DNA与COM+ 分布式应用 VB的详尽语法
FILELIST不是共享内存,它只在Main进程中可见。
SIGCHLD是解决有进程wait不到的方法,但一定要wait,否则会造成很多僵尸进程的存在。
谁对pipe 或线程同步熟悉?!
帮忙看看!
对FILELIST与PROCESS_COUNTER操作的时候加锁了吗
把代码帖出来看看.
int file_num=0;
RWTPtrSlist<RWCString> filelist;
//是用Rogue Wave的库,方法有insert(), get()...认为是数组吧.
mutex_t filelist_mutex;
cond_t filelist_cond; //fork ftp process
if (mutex_init(&filelist_mutex, USYNC_THREAD, NULL)!= 0) {
...
}
//and init all mutex and cond
//creat 2 thread
...
//in readpipe thread
if (mutex_lock(&filelist_mutex)!=0) {
...
}
filelist.insert(...);
file_num++;
if (cond_signal(&filelist_cond)!=0) {
...
}
if (mutex_unlock(&filelist_mutex)!=0) {
...
}//in Main
if (mutex_lock(&filelist_mutex)!=0) {
...
}
while (file_num==0) {
thr_result = cond_wait(&filelist_cond, &filelist_mutex);
if (thr_result!=0) {
if (thr_result!=EINTR) {
exit(0);
}
else {
continue;
}
}
}
filename=filelist.get(); //remove one file name from filelist
file_num--;
if (mutex_unlock(&filelist_mutex)!=0) {
...
}
//then fork1 deal file process to deal filename
mutex_t counter_mutex;
cond_t counter_cond; //fork ftp process
if(signal(SIGCHLD,sig_chld)==SIG_ERR){
...
}
if (mutex_init(&counter_mutex, USYNC_THREAD, NULL)!= 0) {
...
}
//init all mutex and cond//creat read pipe thread//in Main while(1) loop and after get filename
if ( (pid_sql = fork1()) < 0) {
...
}
else if (pid_sql > 0) { /* parent */
if(mutex_lock(&counter_mutex)!= 0) {
...
}
while (process_counter >=max_file_num) {
//max_file_num=30
thr_result = cond_wait(&counter_cond, &counter_mutex);
if (thr_result!=0) {
if (thr_result!=EINTR) {
kill(pid_ftp, SIGUSR1);
exit(0);
}
else
continue;
}
}
}
process_counter++;
if (mutex_unlock(&counter_mutex)!=0) {
...
}
}
//pid_sql==0 child ...
-----------------------------------------------------------------
void sig_chld(int signo){
signal(SIGCHLD,sig_chld);
int status; pid_t pid_son;
if(signo==SIGCHLD){
if(mutex_lock(&counter_mutex)!= 0) {
kill(pid_ftp, SIGUSR1);
exit(1);
}
if(process_counter>0){//目前测试从未<0
//ftp 没计算在process_counter中,如ftp exit,有可能(process_counter--)<0
process_counter--;
}
else{
...
}
if (cond_signal(&counter_cond)!=0) {
kill(pid_ftp, SIGUSR1);
exit(1);
}
if (mutex_unlock(&counter_mutex)!=0) {
kill(pid_ftp, SIGUSR1);
exit(1);
}
if ((pid_son=waitpid(-1,&status,WNOHANG)) > 0) {
if (pid_son == pid_ftp) { //ftp process exit and should exit!
kill(pid_ftp, SIGUSR1);
exit(1);
}
}
else{
...
}
}
return;
}
pipe最大4*1024 or 2*1024