Saturday, 28 September 2013

Performance Issue in Executing Shell Commands

Performance Issue in Executing Shell Commands

In my application, I need to execute large amount of shell commands via
c++ code. I found the program takes more than 30 seconds to execute 6000
commands, this is so unacceptable! Is there any other better way to
execute shell commands (using c/c++ code)?
//Below functions is used to set rules for
//Linux tool --TC, and in runtime there will
//be more than 6000 rules to be set from shell
void CTCProxy::ApplyTCCommands(){
FILE* OutputStream = NULL;
//mTCCommands is a vector<string>
//every string in it is a TC rule
int CmdCount = mTCCommands.size();
for (int i = 0; i < CmdCount; i++){
OutputStream = popen(mTCCommands[i].c_str(), "r");
if (OutputStream){
pclose(OutputStream);
} else {
printf("popen error!\n");
}
}
}

No comments:

Post a Comment