我在我的主进程中使用fork语句创建了一系列子进程,数目不定。
这里是5个,第5个子进程在执行语句
system((char*)("rm "+path+" -Rf").c_str());
非法退出了。但这个语句确实被执行了(因为改路径已经被删除了)
其他4个进程由于条件关系,不执行此句都正常退出了。
以下是代码片断:
switch(this->job_type) {
case 1:
sql = "select id from jobstatus where loaded_time<'" + this->begindate + "' or (loaded_time IS NULL and submit_time<'" + this->begindate + "')";
if (!db_main->ExecTuplesOk(sql.c_str()))
{
debug(db_main->ErrorMessage());
return false;
}
if( db_main->Tuples() <= 0 )
{
debug("not found!\n");
return true;
}
for(int i = 0;i < db_main->Tuples();i++)
{
id_str += ","+string(db_main->GetValue(i,0));
string path = "";
path = live_path + db_main->GetValue(i,0);
DIR * dir;
if((dir=opendir(path.c_str())) == NULL)
continue;
closedir(dir);
// cout<<remove(path.c_str())<<endl;
debug("delete "+ path +" at "+CurrentTime());
system((char*)("rm "+path+" -Rf").c_str());
}
那位达人给我解答一下,万分感谢。
这里是5个,第5个子进程在执行语句
system((char*)("rm "+path+" -Rf").c_str());
非法退出了。但这个语句确实被执行了(因为改路径已经被删除了)
其他4个进程由于条件关系,不执行此句都正常退出了。
以下是代码片断:
switch(this->job_type) {
case 1:
sql = "select id from jobstatus where loaded_time<'" + this->begindate + "' or (loaded_time IS NULL and submit_time<'" + this->begindate + "')";
if (!db_main->ExecTuplesOk(sql.c_str()))
{
debug(db_main->ErrorMessage());
return false;
}
if( db_main->Tuples() <= 0 )
{
debug("not found!\n");
return true;
}
for(int i = 0;i < db_main->Tuples();i++)
{
id_str += ","+string(db_main->GetValue(i,0));
string path = "";
path = live_path + db_main->GetValue(i,0);
DIR * dir;
if((dir=opendir(path.c_str())) == NULL)
continue;
closedir(dir);
// cout<<remove(path.c_str())<<endl;
debug("delete "+ path +" at "+CurrentTime());
system((char*)("rm "+path+" -Rf").c_str());
}
那位达人给我解答一下,万分感谢。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货