Re: problem in invoking shell script through a C++ thread
- From: mugurvinay@xxxxxxxxx
- Date: Mon, 25 Feb 2008 01:44:12 -0800 (PST)
On Feb 23, 8:21 am, Paul Pluzhnikov <ppluzhnikov-...@xxxxxxxxx> wrote:
mugurvi...@xxxxxxxxx writes:
I am facing a problem, while invoking a unix shell script through C++
code. I am using Pthreads to invoke shell scripts. Problem is that the
threadsometime invokes the scripts and sometime doesn't. Around 40%
of the time it fails to invoke the script.
You have supplied no useful info whatsoever.
Let me know your thoughts on this.
Please read this:
http://catb.org/esr/faqs/smart-questions.html
and try asking your question again, only smarter.
In particular:
- Exactly how do you "invoke shell scripts" (system? popen? fork/exec? something else?)
- How do you know that the script didn't get invoked?
- Did thethreadthat was supposed to invoke the script terminate?
If not, is it stuck somewhere? Where?
- Are you using pthread_atfork() handler(s)? If not, should you be?
... etc... etc...
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Hi,
Thanks for looking at my query.
1. I have attached the functions, which I have used to invoke thread,
and in turn to invoke the scripts
2. We have writing log from C++ code as well as from the script which
is being invoked. So, If i look at the C++ trace, I could see a entry
for an object Id (whic is unique) and the corresponding entry is not
present at the script trace file.
3. Since I am using, synchronous mode of ExpSpawnApplication, the
thread will be in block call status, until the script finishes its
work
CODE
bool TeMIPAlarmObjectUser::LaunchThread(Argument* pArgumentObj, const
RWCString& strInfo)
{
TraceMessage << "--> LaunchThread() Alarm ID = " <<
getId().getString() << endl;
bool bErrorOccured= false;
pthread_t threadId;
pthread_attr_t tattr;
int nReturnCode = pthread_attr_init(&tattr);
if (0 == nReturnCode )
{
TraceMessage << "--- LaunchThread() pthread_attr_init success.
Size=" << sizeof(tattr) << endl;
nReturnCode =
pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
if (0 == nReturnCode)
{
nReturnCode = pthread_create(&threadId,&tattr,ExecuteCommand,(void
*)pArgumentObj);
if (0 == nReturnCode)
{
TraceMessage << "--- LaunchThread() " << strInfo << " - THREAD
Successful" << endl;
}
else
{
TraceMessage << "--- LaunchThread(): Unable to launch the thread.
Enrichment Dropped. Error Code= " << nReturnCode << endl;
bErrorOccured= true;
}
}
else
{
TraceMessage << "<-- LaunchThread(): Failed to set
PTHREAD_CREATE_DETACHED attribute. Error Code= " << nReturnCode <<
endl;
bErrorOccured= true;
}
if (true == bErrorOccured)
{
delete pArgs;
TraceMessage << "--- LaunchThread(): Decrementing the Command Count
because the Some Thread Error Occured." << endl;
TeMIPAlarmObjectUser::DecrementCommandCount();
m_Enrichment_Drop_Message="LaunchThread(): Unable to launch the
thread-Enrichment Dropped";
m_IsEnrichmentDropped=true;
TraceMessage << "--- " << m_Enrichment_Drop_Message << endl;
}
nReturnCode = pthread_attr_destroy(&tattr);
if ( 0 == nReturnCode )
{
TraceMessage << "--- LaunchThread(): pthread_attr_destroy success"
<< endl;
}
else
{
TraceMessage << "--- LaunchThread(): pthread_attr_destroy Failed.
Error Code = " << nReturnCode << endl;
}
}
else
{
TraceMessage << "--- LaunchThread(): pthread_attr_init Failed. Error
Code = " << nReturnCode << endl;
}
TraceMessage << "<-- LaunchThread("<< bErrorOccured <<")" << endl;
return bErrorOccured;
}
// This function spawns the script with given arguments.
// This function will be invoked by Thread.
void* TeMIPAlarmObjectUser::ExecuteCommand(void *argList)
{
Argument *arg= (Argument *)argList;
RWCString cmdName=arg->commandName;
RWCString cmdArgs=arg->argList;
delete arg;
EXPSpawnedApplication* unixScript = new
EXPSpawnedApplication("CORR839_APPL",cmdName);
// Spawn synchronously
unixScript->setMode(EXP_K_SYNCHRONOUS);
unixScript->setArgList(cmdArgs);
unixScript->Spawn(false);
unixScript->Delete();
// Decrement Command Count
TeMIPAlarmObjectUser::DecrementCommandCount();
return NULL;
}
.
- Follow-Ups:
- Re: problem in invoking shell script through a C++ thread
- From: Dennis Handly
- Re: problem in invoking shell script through a C++ thread
- References:
- problem in invoking shell script through a C++ thread
- From: mugurvinay
- Re: problem in invoking shell script through a C++ thread
- From: Paul Pluzhnikov
- problem in invoking shell script through a C++ thread
- Prev by Date: Windows Drivers from HP-UX Print Server
- Next by Date: Is 'shared memory' pinned or swappable on HP-UX B.11.23 U ia64?
- Previous by thread: Re: problem in invoking shell script through a C++ thread
- Next by thread: Re: problem in invoking shell script through a C++ thread
- Index(es):
Relevant Pages
|
Loading