Re: problem in invoking shell script through a C++ thread



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;
}
.



Relevant Pages

  • Are sysctl(8) values useful for measuring system resource consumption?
    ... the "developer experience," what resources are thus consumed, and figure ... script that essentailly acts as a bit of "scaffolding" around time; ... the script sets things up to invoke timewith the "-l" flag (so we ...
    (freebsd-performance)
  • Re: My perl script to run arbitrary tasks in parallel
    ... you don't invoke it a few times. ... You can give small ones the .JPG extension as opposed to .jpg. ... I have a big perl script for creating nice HTML indices of directory ... GIF animation based video thumbnails, html index files, RSS feeds etc. ...
    (comp.lang.perl.misc)
  • Monitor file change
    ... Is there a way I can monitor a file, and if it's changed/updated by other ... invoke a certain script immediately. ... Department of Physics and Astronomy ...
    (RedHat)
  • Re: back to html page from php
    ... Jerry Stuckle wrote: ... myCart.php script to get back. ... You mean automatically invoke the shopping cart when you load an html ... I just wanted to know if using the tag is the only way to ...
    (comp.lang.php)
  • Re: Trepanning and Parting Off / Handling URLs
    ... into the command line -- and the command line sees the newlines as end ... Add the following near the beginning of the script: ... I meant that you'd change the script to invoke without command line ... Get URL from current selection. ...
    (rec.crafts.metalworking)

Loading