problem in invoking shell script through a C++ thread

  • Follow


Hi,

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
thread sometime invokes the scripts and sometime doesn't. Around 40%
of the time it fails to invoke the script.

Let me know your thoughts on this.

Thanks
Vinay
0
Reply mugurvinay 2/22/2008 12:58:20 PM

mugurvinay@gmail.com 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
> thread sometime 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 the thread that 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.
0
Reply Paul 2/23/2008 3:21:16 AM


On Feb 23, 8:21=A0am, Paul Pluzhnikov <ppluzhnikov-...@gmail.com> wrote:
> mugurvi...@gmail.com 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:
> =A0http://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? som=
ething else?)
> - How do you know that the script didn't get invoked?
> - Did thethreadthat was supposed to invoke the script terminate?
> =A0 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 =3D " <<
getId().getString() << endl;
	bool bErrorOccured=3D false;
	pthread_t threadId;
	pthread_attr_t tattr;
	int nReturnCode =3D pthread_attr_init(&tattr);
	if (0 =3D=3D nReturnCode )
	{
		TraceMessage << "--- LaunchThread() pthread_attr_init success.
Size=3D" << sizeof(tattr) << endl;
		nReturnCode =3D
pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
		if (0 =3D=3D nReturnCode)
		{
			nReturnCode =3D pthread_create(&threadId,&tattr,ExecuteCommand,(void
*)pArgumentObj);
			if (0 =3D=3D nReturnCode)
			{
				TraceMessage << "--- LaunchThread() " << strInfo << " - THREAD
Successful" << endl;
			}
			else
			{
				TraceMessage << "--- LaunchThread(): Unable to launch the thread.
Enrichment Dropped. Error Code=3D " << nReturnCode << endl;
				bErrorOccured=3D true;
			}
		}
		else
		{
			TraceMessage << "<-- LaunchThread(): Failed to set
PTHREAD_CREATE_DETACHED attribute. Error Code=3D " << nReturnCode <<
endl;
			bErrorOccured=3D true;
		}
		if (true =3D=3D bErrorOccured)
		{
			delete pArgs;
			TraceMessage << "--- LaunchThread(): Decrementing the Command Count
because the Some Thread Error Occured." << endl;
			TeMIPAlarmObjectUser::DecrementCommandCount();
			m_Enrichment_Drop_Message=3D"LaunchThread(): Unable to launch the
thread-Enrichment Dropped";
			m_IsEnrichmentDropped=3Dtrue;
			TraceMessage << "--- " << m_Enrichment_Drop_Message << endl;
		}
		nReturnCode =3D pthread_attr_destroy(&tattr);
		if ( 0 =3D=3D nReturnCode )
		{
			TraceMessage << "--- LaunchThread(): pthread_attr_destroy success"
<< endl;
		}
		else
		{
			TraceMessage << "--- LaunchThread(): pthread_attr_destroy Failed.
Error Code =3D " << nReturnCode << endl;
		}
	}
	else
	{
		TraceMessage << "--- LaunchThread(): pthread_attr_init Failed. Error
Code =3D " << 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=3D (Argument *)argList;
    RWCString cmdName=3Darg->commandName;
	RWCString cmdArgs=3Darg->argList;
	delete arg;
	EXPSpawnedApplication* unixScript =3D 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;
}
0
Reply mugurvinay 2/25/2008 9:44:12 AM

mugurvinay@gmail.com wrote:
> 1. I have attached the functions, which I have used to invoke thread,
> and in turn to invoke the scripts

I'm not sure where you do that.
It would be helpful to have a tusc trace of your application:
tusc -o tusc.out -fpu executable parms ...
0
Reply Dennis 2/27/2008 2:37:09 AM

3 Replies
128 Views

(page loaded in 0.054 seconds)

Similiar Articles:













7/26/2012 8:48:47 PM


Reply: