Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

int Impala::Process::Manager4Posix::Create ( const std::string &  cmdLine,
std::string  application 
) [inline, virtual]

Implements Impala::Process::Manager.

Definition at line 62 of file Manager4Posix.h.

References ILOG_ERROR, ILOG_INFO, mProcesses, Impala::Process::Manager::STATE_RUNNING, and Impala::Process::Manager4Posix::ProcessData::stateCode.

00063     {
00064         ILOG_INFO("Create [" << cmdLine << "][" << application << "]");
00065         pid_t pid = fork();//first fork the process
00066         if(pid==-1)
00067         {
00068             //Handle Error, we couldn't fork
00069             //Use thread safe call(strerror_r) to get error string
00070             char buff[256];
00071             if( strerror_r( errno, buff, 256 ) == 0 ) {
00072                 ILOG_ERROR("Could not fork process"<<buff);
00073             }
00074     
00075         }
00076         else if(pid==0)
00077         {
00078             //This is the child process, we should execute the new program
00079             //inside this process
00080             //call exec()
00081             ILOG_INFO("Child Process Running");
00082             
00084             //POSIX WAY FOR LIMITING CPU TIME
00085             //
00086             //Set the max for CPU Time
00087             //struct rlimit rlim;
00088             //rlim.rlim_cur=rlim.rlim_max = maxSomething;
00089             //setrlimit(RLIMIT_CPU,&rlim);
00091 
00092             
00093             StringList argList(cmdLine,' ');
00094             int argc=argList.size()+1;
00095             if (argc < 2)
00096             {
00097                 ILOG_ERROR("The cmd line must contain at least the name of the application to run");
00098                 abort();
00099             }
00100 
00101             char** argv;
00102             argv = new char*[argc];
00103 
00104             int a=0;
00105             StringList::const_iterator i=argList.begin();
00106             std::string application = *i;
00107             for ( ; i!=argList.end(); i++)
00108             {
00109                 argv[a] = new char[(*i).length() + 1];
00110                 sprintf(argv[a],(*i).c_str());
00111                 a++;
00112 
00113             }
00114             argv[a] = (char*)NULL;
00115             
00116             execvp(application.c_str(),argv);
00117             //exec never returns, if it did, there was an error
00118             char buff[256];
00119             if( strerror_r( errno, buff, 256 ) == 0 ) {
00120                 ILOG_ERROR("Could not start application"<<buff);
00121             }
00122             abort();
00123         }
00124         else
00125         {
00126             //We have the child process id in pid, store it for further control
00127             //of the process
00128             ILOG_INFO("The process is forked, child pid is: "<<pid);
00129             ProcessData data;
00130             data.stateCode = STATE_RUNNING;
00131             mProcesses[pid]  = data;
00132             return pid;
00133         }
00134 
00135     }


Generated on Fri Mar 19 11:37:33 2010 for ImpalaSrc by  doxygen 1.5.1