- 论坛徽章:
- 0
|
unix多进程使用shell sort排序文件的问题
我的文件排序代码如下,请帮忙看看问题在哪里?如何能优化?
9个小时实在是太长了!
谢谢
- while(gi_process[i]!=0)
- {
- if(fork() == 0)
- {
- char cdrsourceid;
- int i_cdrsourceid;
- /*LoginToDB();*/
- LoginToDB("BILL_USER_NAME","BILL_PASS_NAME","CONNECT_STRING");
- gi_process_id = gi_process[i];
- /*MonitorChild(gi_process_id,"分拣子进程开始运行");*/
- GetPreFileName();
- while( OpenCdrFile( &cdrsourceid ) )
- {
- i_cdrsourceid = atoi(&cdrsourceid);
- if( atoi(ptr_shm_drecs+i_cdrsourceid*10))
- {
-
- sprintf( sort_originalfile, "%s/%d_D%04d.SORT" , rgTempFileDir , i_cdrsourceid , preproc_batch);
- sprintf( sort_resultfile, "%s/%d_D%04d.TMP" , rgTempFileDir , i_cdrsourceid, preproc_batch);
- sprintf( sort_comm, "sort -T /bill -k 2 %s >; %s" , sort_originalfile, sort_resultfile );
- sprintf( rm_comm, "rm %s", sort_originalfile);
- MonitorChild(gi_process_id,sort_comm);
- if( system( sort_comm ) != -1)
- {
- if( system( rm_comm ) != -1 )
- {
-
- printf("processid= %d,sort_originalfile=%s\n",gi_process_id,sort_originalfile);
-
- continue;
- }
- else
- {
- printf("Error occur while deleting the file %s\n",sort_originalfile);
- ChildError();
- return -1;
- }
- }
- else
- {
- printf(" Error occur while sorting the file %s\n", sort_originalfile);
- ChildError();
- return -1;
- }
-
- }
-
- }
- DestroyPreFileNameTbl();
- exit(0);
-
-
- }
- else if(i_fork<0)
- {
- perror("fork failed\n");
- system("/bill/prog_source/dispatch/killdisp");
- }
- i++;
- }
复制代码 |
|